jeff5656 Posted February 11, 2010 Share Posted February 11, 2010 I get this 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 'lines WHERE pt_id = '30'' at line 1 Unfortunately this says the syntax error is in line 1, so I don't know actually where the error is. include "connectdb.php"; $id_incr=$row['id_incr']; $query4 = "SELECT * FROM lines WHERE pt_id = '".$id_incr."' "; echo $query4; $srch = mysql_query ($query4) or die (mysql_error()); while ($row2 = mysql_fetch_assoc ($srch)) { But when I comment out the $srch = line, the error goes away. When I echo out $query4, it echos out correctly. Any ideas? It's gotta be something obvious :-) Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/ Share on other sites More sharing options...
sader Posted February 11, 2010 Share Posted February 11, 2010 is your table really called lines and column name is pt_id ? u can tray remove '' around id but I gues that is not the case $query4 = "SELECT * FROM lines WHERE pt_id = $id_incr"; Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010846 Share on other sites More sharing options...
jl5501 Posted February 11, 2010 Share Posted February 11, 2010 just for clarity can you change your query definition line to : $query4 = sprintf("select * from `lines` where pt_id = %s",$id_incr); also had to backtick your table name as lines is a mysql reserved word Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010850 Share on other sites More sharing options...
jeff5656 Posted February 11, 2010 Author Share Posted February 11, 2010 Yep, it's called lines and I have a fieldname called pt_id. Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010853 Share on other sites More sharing options...
jeff5656 Posted February 11, 2010 Author Share Posted February 11, 2010 Oh its a reserved word! I didn't ee that part of your reply. Ok that should do it - I will just rename the table to something else :-) Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010896 Share on other sites More sharing options...
greatstar00 Posted February 11, 2010 Share Posted February 11, 2010 u dont need to rename your table name just put ` ` around table name, or column name ` << left of 1, on top of tab key, same key with ~ Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010899 Share on other sites More sharing options...
jl5501 Posted February 11, 2010 Share Posted February 11, 2010 Yes, like I suggested in my solution. However, it is better not to use reserved words, or spaces in table or colmn names, and then you do not need the backticks and it can save confusion later Link to comment https://forums.phpfreaks.com/topic/191789-syntax-error-in-query/#findComment-1010902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.