Pieter Lategan Posted June 27, 2011 Share Posted June 27, 2011 HI I got the following error can someone help. 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 'movie_year>1990 order by movie_type' at line 1 $query = "Select movie_name, movie_type" . "from movie" . "where movie_year>1990 " . "order by movie_type"; $results = mysql_query ($query) or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
mikosiko Posted June 27, 2011 Share Posted June 27, 2011 echo your query and check if is that what you are expecting Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235558 Share on other sites More sharing options...
Pieter Lategan Posted June 27, 2011 Author Share Posted June 27, 2011 this is my full code <?php //connect to MySQL $connect = mysql_connect ("localhost", "bp5am","bp5ampass") or die ("Hey loser, chech your server connection."); //make sure we're using the right database mysql_select_db("moviesite"); $query = "Select movie_name, movie_type" . "from movie" . "where movie_year>1990 " . "order by movie_type"; $results = mysql_query ($query) or die (mysql_error()); while ($row=mysql_fetch_array($results)) { extract($row); echo $movie_name; echo " - "; echo $movie_type; echo "<br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235562 Share on other sites More sharing options...
fugix Posted June 27, 2011 Share Posted June 27, 2011 is your movie_year field an INT? Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235569 Share on other sites More sharing options...
mikosiko Posted June 27, 2011 Share Posted June 27, 2011 this is my full code .... what I was suggesting to you is echo just your query like: $query = "Select movie_name, movie_type" . "from movie" . "where movie_year>1990 " . "order by movie_type"; // ECHO YOUR QUERY AND VALIDATE IF IT IS WHAT YOU WERE EXPECTING echo "Query : " . $query; //$results = mysql_query ($query) //comment this line for now... uncomment it when you are satisfied with the echo results. Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235570 Share on other sites More sharing options...
PFMaBiSmAd Posted June 27, 2011 Share Posted June 27, 2011 You don't have any white-space in your query statement, after the table name and before the WHERE keyword, which you could have seen if you had done what mikosiko suggested. Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235571 Share on other sites More sharing options...
Pieter Lategan Posted June 28, 2011 Author Share Posted June 28, 2011 yes my movie field is in a int field Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235767 Share on other sites More sharing options...
revraz Posted June 28, 2011 Share Posted June 28, 2011 This is what your query looks like: Select movie_name, movie_typefrom moviewhere movie_year>1990 order by movie_type Quote Link to comment https://forums.phpfreaks.com/topic/240540-you-have-an-error-in-your-sql-syntax/#findComment-1235787 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.