Forum Moderators: coopster

Message Too Old, No Replies

Query Failed: You have an error in your SQL syntax;

Possible SQL problems or other code problems

         

netzero8285

3:20 pm on Apr 16, 2006 (gmt 0)

10+ Year Member



Please help,

I am getting the following error message:
"Query2 failed: 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"

The error occurs when the following code is run:

"...

$cat = $_GET["PROD_CAT"];
$item = $_GET["PROD_ID"];
if(!$cat) { $cat=PROD_CAT; $item=PROD_ID;}

$qry = "Select * from PRODUCT Where PROD_CAT=" . $cat . ";";
$rs = mysql_query($qry) or die ('Query1 failed: ' . mysql_error() . '<br>');

//only one item in ResultSet use?_fetch_array() to move to it
$row = mysql_fetch_array($rs);
$catname = $row["PROD_CAT_NAME"];

$qry = "Select * from PRODUCT Where PROD_ID=" . $item . ";";
$rs = mysql_query($qry) or die ('Query2 failed: ' . mysql_error() . '<br>');

// only one item in ResultSet use?_fetch_array() to move to it
$row = mysql_fetch_array($rs);
$iname = $row["PROD_NAME"];

..."

PROD_ID was created as an int in the Db. I think that makes the quotes properly placed at this point.

dreamcatcher

3:41 pm on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to enclose your query in apostrophes:

$qry = "Select * from PRODUCT Where PROD_CAT='" . $cat . "';
$qry = "Select * from PRODUCT Where PROD_ID='" . $item . "';

Also, why ";"; at the end of your lines?

dc

netzero8285

4:03 pm on Apr 16, 2006 (gmt 0)

10+ Year Member



If I don't include the additional '";', then I get the following error:

"Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING".

I wish I could explain what was going on. All I know is what doesn't happen if I include that piece at the end of the line.

dreamcatcher

6:27 pm on Apr 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




$qry = "Select * from PRODUCT Where PROD_CAT='" . $cat . "'";
$rs = mysql_query($qry) or die ('Query1 failed: ' . mysql_error() . '<br>');

$qry = "Select * from PRODUCT Where PROD_ID='" . $item . "'";
$rs = mysql_query($qry) or die ('Query2 failed: ' . mysql_error() . '<br>');

That should be ok.

dc