Jump to content

My SQL syntax error ?


cyber_alchemist

Recommended Posts

i was making a short php program , and I am stuck in the middle of a error which displays :

 

"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 'WHERE TOUR.tour_type = u43022694_type.tourtype_id AND tour_year > 1990 ' at line 5"

 

Here is my php code:

	// select the tour titles titles and there posted from 1990

	$query = 'SELECT 
		tour_name, tourtype_lable 
		FROM 
			TOUR LEFT JOIN u43022694_type ON tour_type = tourtype_id AND
		WHERE 
			TOUR.tour_type = u43022694_type.tourtype_id AND
			tour_year > 1990
		ORDER BY 
			tour_type';

$result = mysql_query($query, $db) or die(mysql_error($db));

//show results

echo '<table border="1">';
while ($row = mysql_fetch_assoc($result)) {
	echo '<tr>';
	foreach ($row as $value) {
		echo '<td>' . $value . '</td>';
	}
	echo '</tr>';
}

echo '</table>';

 where is my syntax error ??? i checked it many times  :sweat:

Link to comment
https://forums.phpfreaks.com/topic/282525-my-sql-syntax-error/
Share on other sites

 

 

TOUR LEFT JOIN u43022694_type ON tour_type = tourtype_id AND

WHERE

TOUR.tour_type = u43022694_type.tourtype_id AND

remove the AND at the end of the left join line

 

Also you don't need to compare tour_type and tourtype_id again in the where clause as you're doing this comparison in the left join.

Link to comment
https://forums.phpfreaks.com/topic/282525-my-sql-syntax-error/#findComment-1451664
Share on other sites

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.