更新数据库的意外PHP行为

时间:2014-03-31 06:41:21

标签: php mysql sql database

此查询未在我的php代码中使用 id = 0000000001 更新数据库条目。执行此查询后,数据库条目保持原样。

$sql = "UPDATE inventory SET (itemName=$item_name, description=$description, 
    supplierCode=$supplier_code, cost=$cost, price=$sell_price,onHand=$num_on_hand, 
    reorderPoint=$reorder_point, backOrder=$back_order) WHERE id=0000000001;";
$x = $connection->prepare($sql);
$connection->query($sql);

2 个答案:

答案 0 :(得分:1)

$sql = "UPDATE inventory 
        SET itemName='$item_name',
        description='$description', 
        supplierCode='$supplier_code', 
        cost='$cost', 
        price='$sell_price',
        onHand='$num_on_hand', 
        reorderPoint='$reorder_point', 
        backOrder='$back_order' 
        WHERE id='0000000001';";

试试这个。

答案 1 :(得分:0)

试试这个

$x = $connection->prepare("UPDATE inventory SET (itemName=?, description=?, 
    supplierCode=?, cost=?, price=?,onHand=?, 
    reorderPoint=?, backOrder=?) WHERE id=0000000001");
$x->bind_param('ssiiiiii',$item_name,$description,$supplier_code,$cost,$sell_price,$num_on_hand,$reorder_point,$back_order);
$x->execute();

我假设supplierCode, cost,price,onHand,reorederPoint and backOrder are of type int