Hello All,

I am getting 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 '' at line 1" on running my php script.

My SQL Syntex is:

$query = "SELECT (movie_name,movie_year,movie_director,movie_leadactor,movie_type,movie_running_time,movie_cost,movie_takings) FROM movie WHERE movie_id= " . $_GET['movie_id'];

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

I have searched a lot on web, but didn't get any descriptive answer. Why It was happening, what shortcommings are in my code.

Please provide a simple solution, that is easy to understand. Thanks in Advance.

3 Years
Discussion Span
Last Post by EmilyJohnson

probabley your $_GET['movie_id'] is blank

in top of page add few lines to see are u getting proper values or not on ur page

echo "<pre>";
echo "</pre>";

You may also remove parenthesis around columns

Edited by urtrivedi


To recap the above two posts:

// check whether $_GET has any value and if the value is valid
// (you might use some more proper validation depending on the value of the movie ID)
if(isset($_GET['movie_id']) && !empty($_GET['movie_id'])) {
    $query = "SELECT movie_name,movie_year,movie_director,movie_leadactor,movie_type,movie_running_time,movie_cost,movie_takings FROM movie WHERE movie_id= " . mysql_real_escape_string($_GET['movie_id']);
    $result = mysql_query($query, $db) or die(mysql_error($db));
} else {
    echo 'The movie ID is missing!';

And please note: mysql extension is a bit old and is about to become a history. Switch to mysqli or even better, the PDO.

Edited by broj1


Thanks to all Daniweb Community for solving my issue (especially @urtrivedi, @pzuurveen, @broj1 ) for supporting to solve the issue.

Actually I was getting this error because $_GET['movie_id'] is blank/Not getting proper values.

Thanks Once Again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.