MYSQL错误-使用PHP For循环

MYSQL错误-使用PHP For循环,php,mysql,Php,Mysql,我知道当涉及语法错误时不应该问问题,但是,我完全不知道为什么会抛出以下错误: PHP和MYSQL代码 //Possible size array to loop through when checking quantity $con_size = array (26,28,30,32,33,34,35,355,36,365,37,375,38,385,39,395, 40,405,41,415,42,425,43,435,44,445,45,

我知道当涉及语法错误时不应该问问题,但是,我完全不知道为什么会抛出以下错误:

PHP和MYSQL代码

//Possible size array to loop through when checking quantity
    $con_size = array (26,28,30,32,33,34,35,355,36,365,37,375,38,385,39,395,
                       40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
    $arrayLength=count($con_size);

        for($x=0;$x<$arrayLength;$x++)
        {

    // check if size is available
    if($line['quantity_c_size_'.$con_size[$x].'_con_b'] > 0 )
    {

        $quantity = $line['quantity_c_size_'.$con_size[$x].'_con_b'];
        $current = $line['quantity_c_size_'.$con_size[$x]];
        $id = $line ['product_id'];


        $data = "UPDATE product_test
        SET quantity_c_size_$con_size[$x] = $quantity + $current,
        quantity_c_size_$con_size[$x]_con_b = 0
        WHERE product_id = $id";

        $result2 = mysql_query($data);

        if ($result2)
        {
            echo 'Stock Updated <br />';
        }
        else
        {
            echo mysql_error();
            echo '<br />';
        }
    }
}
我已经在PHPMyAdmin中使用上面相同的
UPDATE
语法尝试了MYSQL查询,查询成功完成。但是,当它在PHP FOR循环中运行时,会抛出上述错误

我可能遗漏了一些非常明显的东西,但现在我很困惑


有什么建议吗?感谢

按照Andrew的建议,我回传了更新查询,发现
$current
变量为空,因此语句中的加法计算无法完成

我对守则作了如下修订:

//Possible size array to loop through when checking quantity
    $con_size = array (26,28,30,32,33,34,35,355,36,365,37,375,38,385,39,395,
                       40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
    $arrayLength=count($con_size);

        for($x=0;$x<$arrayLength;$x++)
        {

    // check if size is available
    if($line['quantity_c_size_'.$con_size[$x].'_con_b'] > 0 )
    {

        $quantity = $line['quantity_c_size_'.$con_size[$x].'_con_b'];

        if ($line['quantity_c_size_'.$con_size[$x]] == NULL)
        {
            $current = '0';
        }
        else
        {
            $current = $line['quantity_c_size_'.$con_size[$x]];

        }

        $id = $line ['product_id'];


        $data = "UPDATE product_test
        SET quantity_c_size_{$con_size[$x]} = $quantity + $current,
        quantity_c_size_{$con_size[$x]}_con_b = 0
        WHERE product_id = $id";

        ...
//检查数量时循环通过的可能大小数组
$con_size=阵列(26,28,30,32,33,34,35355,36365,37375,385,39395,
40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
$arrayLength=计数($con_大小);
对于($x=0;$x 0)
{
$quantity=$line['quantity\u c\u size.'$con\u size[$x]。'u con\u b'];
如果($line['quantity\u c\u size.'$con\u size[$x]]]==NULL)
{
$current='0';
}
其他的
{
$current=$line['quantity\u c\u size.'$con\u size[$x]];
}
$id=$line['product_id'];
$data=“更新产品\u测试
设置数量{$con_size[$x]}=$quantity+$current,
数量\u c\u大小\u{$con\u大小[$x]}\u con\u b=0
其中product_id=$id”;
...

回显查询并向我们显示它生成的内容。不能简单地使用“数量大小”$con大小[$x]”。必须使用“数量大小”$con大小[$x]”;我强烈怀疑它不喜欢数组表示法。首先从数组中提取变量,将它们分配给变量,并在
$data
字符串中使用这些变量。或者使用大括号:“quantity__________大小{$con_大小[$x]}…”或者更好,将
{/code>包装为
quantity____大小{$con u大小[$x]}
//Possible size array to loop through when checking quantity
    $con_size = array (26,28,30,32,33,34,35,355,36,365,37,375,38,385,39,395,
                       40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
    $arrayLength=count($con_size);

        for($x=0;$x<$arrayLength;$x++)
        {

    // check if size is available
    if($line['quantity_c_size_'.$con_size[$x].'_con_b'] > 0 )
    {

        $quantity = $line['quantity_c_size_'.$con_size[$x].'_con_b'];

        if ($line['quantity_c_size_'.$con_size[$x]] == NULL)
        {
            $current = '0';
        }
        else
        {
            $current = $line['quantity_c_size_'.$con_size[$x]];

        }

        $id = $line ['product_id'];


        $data = "UPDATE product_test
        SET quantity_c_size_{$con_size[$x]} = $quantity + $current,
        quantity_c_size_{$con_size[$x]}_con_b = 0
        WHERE product_id = $id";

        ...