javascript - 我怎样才能分别更新php查询几个不同的值?

标签 javascript php jquery mysql

我必须分别修改/更新两个不同的输入值。问题在于,它们$_GET不会单独更新相同的值,而且它们都获得输入更新查询执行的值(因为请求值相同。。我知道)。我的问题是,如何在查询中获得不相同的值时分别更新它们。我必须更改$_REQUEST还是必须做出if()语句? PS我的代码示例都在一起,并且一点点关闭,但不是在真正的PHP失败

<td class="stock" id="'.$r["product_id"].'">'.STRIPSLASHES($r["product_in_stock"]).'</td>
<td class="test" id="'.$r["product_id"].'"><font size=+2><b>'.$r["product_s_desc"].'</b></font></td>


    <script>
var x;
var h = 0; // blur fires multiple times, use h to count and fire once
var url = 'up.php';

$(".test").on('click', function(d) { 
    d.stopPropagation();
    var x = $(d.target); 
    x.html('<input  id="edit" style="width: 40px;" value="'+x.text()+'">'); 
    var this_id = x.context.id;

    $("#edit").on('blur', function(d) { 
        if (h < 1) {
            h = h+1;
            d.stopPropagation();

            $(d.target.parentElement).text(d.target.value);

            $.get(url,  {id: this_id, value: d.target.value})
                .done(function(d){ if(d == undefined || d != 1) { alert('Something went wrong, check your data and results. '+d);}})

            $("#edit").off('blur');
        }

        return false;
    }); 
    h = 0;
});
</script>

<script>
var x;
var h = 0; // blur fires multiple times, use h to count and fire once
var url = 'up.php';

$(".stock").on('click', function(d) { 
    d.stopPropagation();
    var x = $(d.target); 
    x.html('<input  id="edit2" style="width: 40px;" value="'+x.text()+'">'); 
    var this_id = x.context.id;

    $("#edit2").on('blur', function(d) { 
        if (h < 1) {
            h = h+1;
            d.stopPropagation();

            $(d.target.parentElement).text(d.target.value);

            $.get(url,  {id: this_id, value: d.target.value})
                .done(function(d){ if(d == undefined || d != 1) { alert('Something went wrong, check your data and results. '+d);}})
                .fail(function(d){ alert('error');});
            $("#edit2").off('blur');
        }

        return false;
    }); 
    h = 0;
});
</script>


require_once('db.php');


    $q2= 'UPDATE prestashop.ps_stock_available SET quantity = %d WHERE id_product = %d';
    $q= 'UPDATE prestashop.ps_product SET location = '%s' WHERE id_product = %d';



    $sql = sprintf($q,  $_REQUEST['value'], $_REQUEST['id']);
    $sql2 = sprintf($q2,  $_REQUEST['value'], $_REQUEST['id']);

    $rs=$ib->exec($sql);
    $rs=$ib->exec($sql2);
    if (PEAR::isError($rs)) throw new Exception ("DB Request: ". $rs->getMessage());

    die("1"); // exit and return 1 on success

} catch (Exception $e) {
    print $e->getMessage();
}

最佳答案

我知道这是一种不安全的方法,但是我使用了不同的请求值和if(empty)

关于javascript - 我怎样才能分别更新php查询几个不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42146495/

相关文章:

PHP/MySQL 如何通过管理面板确定表中行的优先级

php - MySQL 将数据插入数据库时​​影响行 -1

jquery - z-index 在淡入淡出过渡期间不起作用,在过渡完成后解析

javascript - on.input 太快了!是否有多字符输入事件? ..或者添加计时器的方法

java - 如何在 webapp 中查看我的 index.html 文件,该文件是从 url 上的 swagger ui 克隆的

javascript - 计算机进入休眠状态后,Chrome/Javascript SetTimeout 卡住了

php - 使用坐标对查找半径的存储过程

javascript - MVC - Kendo 模板在使用特殊语言字符时出现错误

javascript - 如何扩展 Ivan Sanchez 的 Leaflet.Polyline.SnakeAnim 以支持 'snakepause' 和 'snakeplay' 事件

javascript - 类型错误 : Object doesn't support property or method 'entries' (IE11)