更新mysql无法正常工作

时间:2014-03-29 23:04:37

标签: php mysql sql

我在本地服务器上尝试了这个脚本并且它工作正常,但它没有更新我的表记录并且没有给我任何MySQL错误。有人可以帮帮我吗?

ini_set("allow_url_fopen", 1);
$connect = mysqli_connect('localhost','Username','Password','Database')
    or die('Could    not connect: ' . mysqli_error($connect));
$handle_source = fopen('http://media.jgoodin.com/dropship/jgi-inventory.csv', 'r');

//updating regular product
while (($data = fgetcsv($handle_source, 500, ",")) !== false)
{
    $VendorSKU = $data[0];
    $onHand = $data[1];

    if ($result = mysqli_query($connect,"SELECT reference
        FROM ps_product WHERE reference='$VendorSKU'"))
        {
            if ($line = mysqli_fetch_assoc($result, MYSQL_ASSOC))
            {
                mysqli_query($connect,"UPDATE ps_product
                    SET quantity='$onHand'
                    WHERE reference='$VendorSKU'");     

                echo "UPDATE ps_product
                    SET quantity='$onHand'
                    WHERE reference='$VendorSKU'","<br>";
            }   
            mysqli_free_result($result);
        }
}
fclose($handle_source);
mysqli_close($connect);

1 个答案:

答案 0 :(得分:0)

将您的更新通话更改为:

if (!mysqli_query($connect, 'UPDATE ps_product
    SET quantity=' . intval($onHand, 10) . '
    WHERE LOWER(trim(reference))=\'' . strtolower(trim(mysqli_real_escape_string($connect, $VendorSKU))) . '\''))
{
    die(mysqli_error($connect));
}

另外,您可以删除检查产品是否存在 - 它是无用的