Php SQL语法错误,很可能是“我的值”
我当前收到错误消息Php SQL语法错误,很可能是“我的值”,php,mysql,sql,Php,Mysql,Sql,我当前收到错误消息 Could not enter data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order(quantity, product)VALUES ( "number", "text")' at line 1 代码如下: <?php requi
Could not enter data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order(quantity, product)VALUES ( "number", "text")' at line 1
代码如下:
<?php
require_once('../../config/db.php');
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if(! $conn )
{
die('Error with database connection: ' . mysql_error());
}
$sql = 'INSERT INTO order'.
'(quantity, product)' .
'VALUES ( "number", "text")';
mysql_select_db('order');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
使用blockquotes`作为转义字符,以便在sql中为字符串值使用保留字,如order使用单引号,而不是双引号。那么让我们试着这样做:
$sql='INSERT INTO order'。
"(数量,产品)"。
“值(\'number\',\'text\')”;
还是像这样
$sql=“插入订单”。
“(数量、产品)”。
“值(‘数字’、‘文本’)”;
其次,如果“数量”的类型是数字,则在其中传递一个数字值:
$sql=“插入订单”。
“(数量、产品)”。
“值(100500,‘文本’)”;
您需要在表格名称后加引号,订单保留word@RoyalBg谢谢,问题解决了!这里有一个更好的主意-更改表名!在MySQL中,双引号或单引号都可以容纳字符串。这里的字符串不仅仅存在于MySQL中
'INSERT INTO `order` '.
'(quantity, product)' .
'VALUES ( "number", "text")';