Jump to content

Can't find syntax error


ondi

Recommended Posts

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>
";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/153651-cant-find-syntax-error/
Share on other sites

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.

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

 

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:

 

jskd4g.jpg[/code]

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 {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.