Error1f1f
Error1f1f

Reputation: 539

Mysqli Query is not returning any result

I seem to be having trouble getting mysqli to return a result from my query. My code is:

$db_conn = get_database(); //function returns a static mysqli object reference

if($result = $db_conn->query("SELECT city 
                                FROM state 
                               WHERE name='CA' ")) {
  $row = $result->fetch_object();
  $city= $row->city;
  $result->close();
} else {
  echo $db_conn->error;
}

When I echo the contents of the city variable, it contains nothing.

Upvotes: 1

Views: 545

Answers (1)

onteria_
onteria_

Reputation: 70487

  1. Check get_database() to make sure the proper database is selected
  2. The column state in your where clause is the same as your table name, state. Change that to name instead if you can.

Upvotes: 1

Related Questions