-1

这是我的代码

for ($m = 1; $m <= $j; $m++)
    {
        if ($_POST['item_id".$m."'] > 0)
        {
        mysqli_query($con,"UPDATE Orders SET ProductID = '$_POST['item_id".$m."']' WHERE PO = '$k'");
        mysqli_query($con,"UPDATE Orders SET Product_Name = '$_POST['item_name".$m."']' WHERE PO = '$k'");
        mysqli_query($con,"UPDATE Orders SET Quantity_Ordered = '$_POST['item_qty".$m."']' WHERE PO = '$k'");
        }
    }

但我明白了

语法错误,意外的 T_ENCAPSED_AND_WHITESPACE,需要 T_STRING 或 T_VARIABLE 或 T_NUM_STRING

我也试过

mysqli_query($con,"UPDATE Orders SET ProductID = '$_POST['item_qty$m']' WHERE PO = '$k'");

得到相同的结果。

有人可以帮助我吗?谢谢>-:

4

3 回答 3

1

您的报价没有正确平衡。修复它们会给你这个:

for ($m = 1; $m <= $j; $m++)
{
    if ($_POST["item_id".$m] > 0)
    {
       mysqli_query($con,"UPDATE Orders SET ProductID = '" . $_POST["item_id".$m]   . "' WHERE PO = '$k'");
       mysqli_query($con,"UPDATE Orders SET Product_Name = '" . $_POST["item_name".$m] . "' WHERE PO = '$k'");
       mysqli_query($con,"UPDATE Orders SET Quantity_Ordered = '" . $_POST["item_qty".$m]  . "' WHERE PO = '$k'");
    }
}
于 2013-04-02T17:42:32.553 回答
0

您必须转义 MySQL 查询中的变量:

    mysqli_query($con,"UPDATE Orders SET ProductID = '$_POST['item_id".$m."']' WHERE PO = '$k'");

    mysqli_query($con,"UPDATE Orders SET ProductID = '". $_POST['item_id".$m."'] . "' WHERE PO = '$k'");

其他人也一样。全部一起:

mysqli_query($con,"UPDATE Orders SET ProductID = '". $_POST['item_id".$m."'] . "' WHERE PO = '$k'");
mysqli_query($con,"UPDATE Orders SET ProductID = '". $_POST['item_name".$m."'] ."' WHERE PO = '$k'");
mysqli_query($con,"UPDATE Orders SET ProductID = '". $_POST['item_qty".$m."'] ."' WHERE PO = '$k'");
于 2013-04-02T17:38:30.070 回答
0

也许是这样?

for ($m = 1; $m <= $j; $m++) {
    $item = $_POST['item_id' . $m];
    if ($item > 0) {
        $itemName = $_POST['item_name' . $m];
        $itemQty = $_POST['item_qty' . $m];
        mysqli_query($con, "UPDATE Orders SET ProductID = '" . $item . "' WHERE PO = '" . $k . "'");
        mysqli_query($con, "UPDATE Orders SET ProductID = '" . $itemName . "' WHERE PO = '" . $k . "'");
        mysqli_query($con, "UPDATE Orders SET ProductID = '" . $itemQty . "' WHERE PO = '" . $k . "'");
    }
}
于 2013-04-02T17:44:05.657 回答