ondi Posted April 11, 2009 Share Posted April 11, 2009 Hi, I'm trying to write my own code for the first time, but can't get over 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 'MD.homeaway AS venue, MD.level AS level MD.contact AS contact FROM matchdetails ' at line 6 Here is my code. Can someone have a look? Line 6 is only connection details, which are all correct. <?php $host = 'localhost'; $user = 'user'; $password = 'password'; $txt_db_name = 'web176-findme'; $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); $get_report = mysql_query(" SELECT MD.matchid AS matchid, DATE_FORMAT(M.date, '%W %d %b') AS match_date, DATE_FORMAT(M.date, '%H:%i') AS clock, MD.teamname AS teamname MD.homeaway AS venue, MD.level AS level MD.contact AS contact FROM matchdetails MD, WHERE MD.date < CURRENT_TIMESTAMP AND ORDER BY M.MatchDateTime DESC LIMIT $range ", $connection) or die(mysql_error()); { echo"<center> $data[match_date], $data[clock]<br> $data[teamname]<br> $data[venue] $data[level] - $data[contact] Attendance: $data[crowd]<br> <a href=\"stats/matchdetails.php?id=$data[id]\"></a><a href=\"http://www.walthamforest-fc.co.uk/stats/matchdetails.php?id=$data[id]#report\">Match Report</a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 11, 2009 Share Posted April 11, 2009 There are two missing commas in your list of SELECT items. Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807393 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 11, 2009 Share Posted April 11, 2009 MySQL refer to line 6 within the MySQL query not into the php file. It probably having something to do with a missing comma , on line 5, 7 with a MD, on line 9 and the AND on line 10. Try to get your query working into phpmyadmin before putting it into php it may help. Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807394 Share on other sites More sharing options...
ondi Posted April 11, 2009 Author Share Posted April 11, 2009 My code now looks something like this <?php $host = 'localhost'; $user = 'web176-findme'; $password = 'arsenal'; $txt_db_name = 'web176-findme'; $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); $get_report = mysql_query(" SELECT MD.matchid AS matchid, DATE_FORMAT(M.date, '%W %d %b') AS match_date, DATE_FORMAT(M.date, '%H:%i') AS clock, MD.teamname AS teamname MD.homeaway AS venue, MD.level AS level, MD.contact AS contact, FROM matchdetails MD, WHERE MD.date < CURRENT_TIMESTAMP AND ORDER BY MD.date DESC LIMIT $range ", $connection) or die(mysql_error()); { echo"<center> $data[match_date], $data[clock]<br> $data[teamname]<br> $data[venue] $data[level] - $data[contact] Attendance: $data[crowd]<br> "; } ?> But still with the 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 'MD.homeaway AS venue, MD.level AS level, MD.contact AS contact, FROM matchdetail' at line 6 Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807395 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 You're still missing a comma after teamname and you also have a comma after contact and MD that shoudln't be there. Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807407 Share on other sites More sharing options...
ondi Posted April 11, 2009 Author Share Posted April 11, 2009 Thanks crayon, i now have errorless code but nothing prints! Here is my code: <?php $host = 'localhost'; $user = 'web176-findme'; $password = 'arsenal'; $txt_db_name = 'web176-findme'; $connection = mysql_connect("$host","$user","$password") or die(mysql_error()); mysql_select_db("$txt_db_name",$connection) or die(mysql_error()); $get_report = mysql_query(" SELECT MD.matchid AS matchid, DATE_FORMAT(MD.date, '%W %d %b') AS date, DATE_FORMAT(MD.date, '%H:%i') AS clock, MD.teamname AS teamname, MD.homeaway AS venue, MD.level AS level, MD.contact AS contact FROM matchdetails MD ORDER BY MD.date DESC ", $connection) or die(mysql_error()); { echo"<center> $data[date]<br> $data[teamname]<br> $data[venue] $data[level] - $data[contact] "; } ?> and an image of the data in my table: [/code] Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807412 Share on other sites More sharing options...
.josh Posted April 11, 2009 Share Posted April 11, 2009 okay well looking farther down your code, you perform the query but you don't actually retrieve anything from the result source. $get_report is the result source from your query. You need to use a mysql_fetch_xxx function to retrieve the data from it. Usually people put it into a while loop. I see you have $data[...] inside brackets. Looks like you somehow managed to lose your while loop. It probably looked like this: while($data = mysql_fetch_assoc($get_report)) That would go just before the { Quote Link to comment https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/#findComment-807416 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.