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.

Recommended Answers

All 2 Replies

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

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

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.