Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 07: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, 07:58
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 5,444
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";";
__________________
Warning
May! contain traces of NUT. people with NUT allergies should not pay attention to any of the above
Reply With Quote
  #3 (permalink)  
Old 06-10-08, 01:44
topcat2 topcat2 is offline
Registered User
 
Join Date: Jun 2008
Posts: 6
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' ";
__________________
SQL Tutorial
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

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