0

I keep getting this error when I try to run and print out the results of my database query. I know that this error usually mean that my query failed but i can't figure out what is wrong with it.

$genre=readline("Enter Genre: ");
  $query = "SELECT movie_title FROM movie WHERE movie_genre = $genre";
  $result = $db_obj->query("$query");
  while($row = mysql_fetch_array($result)){
        echo $row['movie_title']. " - ". $row['movie_genre'];
        echo "\n";
        }

I've even tried just using "SELECT movie_title FROM movie" to see if it would work without the variable but it still gave me the same error.

3
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

Replace this part of your code ...

$query = "SELECT movie_title FROM movie WHERE movie_genre = $genre";

with this...

$query = "SELECT movie_title FROM movie WHERE movie_genre = '".$genre."'";

Hope that it will work..

0

tomato is right.
If field is integer then you can direct use php variable but here you have to use single quote.

This topic has been dead for over six months. 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.