如何更新php查询多个不同的值?

时间:2017-02-09 20:43:09

标签: javascript php jquery mysql

我必须单独修改/更新两个不同的输入值。问题是因为他们$_GET他们不会单独更新相同的值,他们都得到输入更新查询执行的值(因为相同的请求值..我知道)。我的问题是如何单独更新它们,因为查询时没有获得相同的值。我是否必须更改$_REQUEST或我必须发表if()声明? PS我的代码示例是一起而且有点关闭,但不是真正的php failes

<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();
}

1 个答案:

答案 0 :(得分:0)

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