我用它来处理PHP。
错误: -
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 '' at line 1
编辑1:
$SQLQUERY = sprintf("SELECT pd_serial FROM product_details WHERE pd_model_type=%s AND pd_model_name=%s AND pd_model_version=%s AND pd_product_group=%s LIMIT 1",
GetSQLValueString($modeltype, "text"),
GetSQLValueString($modelname, "text"),
GetSQLValueString($modelversion, "text"),
GetSQLValueString($modelgroup, "text"));
$QUERYEXEC = mysql_query($SQLQUERY, $dacreint) or die("OOPS! Please try again.");
while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
{
$pdserial = $QUERYFETCH['pd_serial'];
}
编辑2:
while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
{
$pdserial = $QUERYFETCH['pd_serial'];
}
$SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no = '$product_serial_no'");
$TCcount_QE = mysql_query($SQLQUERY, $dacreint) or die(mysql_error());
答案 0 :(得分:2)
您应该将字符串放在单引号内。并确保使用mysql_real_escape_string()
或类似函数
SELECT pd_serial FROM product_details WHERE (pd_model_type='%s' AND pd_model_name='%s') AND (pd_model_version='%s' AND pd_model_group='%s') LIMIT 1
更新1
while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
{
$pdserial = $QUERYFETCH['pd_serial'];
}
// let's comment out the following line
// $SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no = '$product_serial_no'");
// and modifying it as:
$SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no = %s", GetSQLValueString($product_serial_no, "text"));
$TCcount_QE = mysql_query($SQLQUERY, $dacreint) or die(mysql_error());
答案 1 :(得分:0)
您能否添加“呈现”查询?您的参数是否应在引号中设置为“%s”?
顺便说一下:你不必在完全“AND”链接的WHERE语句中设置括号。
答案 2 :(得分:0)
这是正确的查询
SELECT pd_serial FROM product_details WHERE pd_model_type=%s AND pd_model_name=%s AND pd_model_version=%s AND pd_model_group=%s LIMIT 1
被修改
SELECT pd_serial FROM product_details WHERE pd_model_type like '%s' AND pd_model_name like '%s' AND pd_model_version like '%s' AND pd_model_group like '%s' LIMIT 1
对不起,我忘了在括号中附上类似的条件,因为我们在这里使用外卡而我失踪了