MySQLI的问题

时间:2015-06-06 09:24:24

标签: php mysql mysqli

我可能太累了,看了一个小错误,但是这段代码不会在我的数据库中输入任何信息。

$sql = "INSERT INTO TABLE_NAME (UPC, Description, Make, Model, SNLocation, IMEI_MEID, Resetting, Notes, Image)

VALUES ($UPC, $Desc, $Make, $Model, $SNLocation, $IMEI_MEID, $Resetting, $Notes, $Image)";

mysqli_query($con, $sql) or die(mysqli_error($sql));

有人可以帮我检查一下这是否存在语法问题?

2 个答案:

答案 0 :(得分:1)

因为你有错误

$sql = "INSERT INTO TABLE_NAME (UPC, Description, Make, Model, SNLocation, IMEI_MEID, Resetting, Notes, Image)  

VALUES ('$UPC', '$Desc', '$Make', '$Model', '$SNLocation', '$IMEI_MEID', '$Resetting', '$Notes', '$Image')";

Notes, Image)] <-----移除] ,并且需要引用值

答案 1 :(得分:1)

您需要删除]并用单引号(')括起字符串值:

$sql = "INSERT INTO TABLE_NAME
       (UPC, Description, Make, Model, 
       SNLocation, IMEI_MEID, Resetting, Notes, Image)] <-- Here --> 

VALUES ($UPC, $Desc, $Make, $Model, $SNLocation, $IMEI_MEID, $Resetting, $Notes, $Image)";

mysqli_query($con, $sql) or die(mysqli_error($sql));