Reputation: 3025
I am using it to do with PHP.
ERROR:-
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
EDIT 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'];
}
EDIT 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());
Upvotes: 1
Views: 1094
Reputation: 1601
You should put strings within single quotes. And make sure you have escaped those string values using mysql_real_escape_string()
or similar function
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
UPDATE 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());
Upvotes: 2
Reputation: 19882
Here is the correct query
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
Edited
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
Sorry i forgot to enclose like condition in brackets and i was missing like because we are using wild card here
Upvotes: 0
Reputation: 416
Could you please add the "rendered" query? Are your parameters, which should be set in "%s" set in quotes?
by the way: you don't have to set the parentheses inside a completely "AND"-linked WHERE-statement.
Upvotes: 0