PHP foreach mysql行更新

时间:2017-05-07 17:55:56

标签: php mysql foreach

foreach($_POST['categ_name'] as $key => $categ)
{
    $beg = $_POST['beg_count'][$key];
    $del = $_POST['del_count'][$key];
    $ret = $_POST['ret_count'] [$key];
    $exc = $_POST['exc_count'] [$key];
    $pout = $_POST['pout_count'] [$key];
    $sales = $_POST['sales_count'] [$key];
    $end = $_POST['end_count'] [$key];
    $actual = $_POST['actual_count'] [$key];
    $var = $_POST['variance'] [$key];

        $sql = $conn->prepare("UPDATE `inventory_report_count` SET `beg` = '$beg' , `del` = '$del' , `ret` = '$ret' , `exc` = '$exc' , `po` = '$pout' ,`sales` = '$sales' ,`end` = '$end' ,`actual_count` = '$actual' ,`variance` = '$var' WHERE `categ_name` = '$categ' ");
        $sql -> execute();
}

当我在localhost上运行上面的代码时,没有任何更新,但是当我试图回显循环中的所有变量时,我得到了所有正确的值。谁能在这里轻松一点?

提前致谢!

编辑:修复它。似乎$ categ的值在末尾包含一个额外的空格,因此它与db中的值不匹配。

0 个答案:

没有答案