Alicia Posted March 17, 2009 Share Posted March 17, 2009 Hi, I encounter 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 '' at line 1 on this query : $result = mysql_query("SELECT * FROM `vrequest` WHERE `type`='student now' AND `to`='$id'") or die(mysql_error()); I have checked multiple times and really have no idea whats wrong with this simple query. please advise. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/ Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 what is the value of $id? what does this output: $sql = "SELECT * FROM `vrequest` WHERE `type`='student now' AND `to`='$id'"; print $sql; $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786853 Share on other sites More sharing options...
Alicia Posted March 17, 2009 Author Share Posted March 17, 2009 number-- e.g : 1, 21, 311 and etc SELECT * FROM `vrequest` WHERE `type`='student now' AND `to`='1' Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786858 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 well...i don't see anything semantically wrong with your code. again, do the print $sql code to make sure the value of $id is what you expect. also, try changing this: die(mysql_error()); to something more distinguishing: die("Failed to SELECT from vrequest: ".mysql_error()); just to make sure that is the actual point of failure Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786865 Share on other sites More sharing options...
Alicia Posted March 17, 2009 Author Share Posted March 17, 2009 yes., $id is the value i am expecting.. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786901 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 if you echo the query, and copy/paste it into phpMyAdmin (or whatever you use to manage your DB), does it work? Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786907 Share on other sites More sharing options...
Alicia Posted March 17, 2009 Author Share Posted March 17, 2009 yes,, it works in phpmyadmin Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786970 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 well...there is nothing wrong with the code you posted. further remediation: 1) Make sure you are definitely looking at the place where the problem is 2) Make sure your quotes are copied from MS Word...it uses different quotes. Just to be safe, open the file in a basic text editing (like notepad), then delete each quote and type it back in...just to make sure. it sounds silly, but a lot of problems are caused by this. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786976 Share on other sites More sharing options...
PFMaBiSmAd Posted March 17, 2009 Share Posted March 17, 2009 Unless $id contained something with a single-quote in it, nothing you have posted so far would generate that error. Does your code contain any other queries and what is the code that produces $id, both originally in your form or link and how is it processed before being put into the query? Show all your code to get the quickest solution. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786983 Share on other sites More sharing options...
fenway Posted March 17, 2009 Share Posted March 17, 2009 Show all your code to get the quickest solution. Maybe *all* isn't the best idea -- isolate the query first. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786990 Share on other sites More sharing options...
Alicia Posted March 17, 2009 Author Share Posted March 17, 2009 thats all I have in my script with $id ='1'; tried $id ="1"; $id =1; still showing the same error even i replaced * with column names and remove the where clause... a simple query like select * from vrequest caused the same error too.. oh gosh, what happened to my computer,, is it computer prob or what Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-786995 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 do other queries work? cus again, there is nothing semantically wrong with your code. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-787000 Share on other sites More sharing options...
fenway Posted March 19, 2009 Share Posted March 19, 2009 Start again -- new file, new script -- run a simple query, make sure it works. Quote Link to comment https://forums.phpfreaks.com/topic/149841-sql-error/#findComment-788261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.