Jump to content

My SQL syntax error ?


Go to solution Solved by Ch0cu3r,

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

  • Solution

 

 

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.