If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > syntax error with my select statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-04-08, 06:20
kennyola kennyola is offline
Registered User
 
Join Date: May 2008
Posts: 6
hello,
please can someone help me with this query. It says there is syntax error with my select statement


$exam = $_GET['ex'];
$cur = $_GET['cur'];
$tp = $_GET['tps'];



mysql_select_db($database_ecertConn, $ecertConn);
$query_Recordset1 = "SELECT topics.topic, topics.name FROM topics WHERE excode='$exam' cocode='$cur' AND tpcode='$tps' ";
$Recordset1 = mysql_query($query_Recordset1, $ecertConn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
Reply With Quote
  #2 (permalink)  
Old 06-04-08, 06:58
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
please don't hijack a thread, if its a new question start a new thread
if its a PHP problem ask it in the PHP forum

I thought MySQL used the " to delimit strings
you are also missing and AND int he where clause
and you are also missing the terminating semicolon
Code:
$query_Recordset1 = "SELECT topics.topic, topics.name FROM topics WHERE excode=\"$exam\ AND" cocode=\"$cur\" AND tpcode=\"$tps\";" ;
Whenever you have problems with SQL, especially if you are building the SQL using parameters or variables from elsewhere it generally pays to display the sql somewhere so you can make sure what you are sending to the SQL engine is actually what you think it is. It also helps if you assing the SQL to a variable (say $strSQL).

you could do this using the or die construct

or die(echo " The SQL is:".$strSQL; )

some people prefer to separate the lines so its easier to read
Code:
$query_Recordset1 = "SELECT topics.topic, topics.name FROM topics
 WHERE excode="$exam"
 AND cocode="$cur'
 AND tpcode="$tps";";
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 06-10-08, 00:44
topcat2 topcat2 is offline
Registered User
 
Join Date: Jun 2008
Posts: 7
You are missing an AND between '$exam' and cocode. The correct statement should be:

$query_Recordset1 = "SELECT topics.topic, topics.name FROM topics WHERE excode='$exam' AND cocode='$cur' AND tpcode='$tps' ";
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On