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.

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>";
print_r($_GET);
echo "</pre>";

You may also remove parenthesis around columns

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.