mysql - PHP MySQLi Fatal error: Call to a member function fetch_array() on a non-object in -
getting error , not sure what's going on. new using mysqli.
$query = 'select name, email us__users state="' . $state . '" order zip asc limit 5'; $result = $mysqli->query($query); while ($row = $result->fetch_array()) { print ($row['name'] . ' ' . $row['email']); } $result->free(); there's 1 row in mysql db. however, when re-create $query , run @ mysql command prompt, queries fine , displays 1 result.
the query string syntactically incorrect. have this:
$query = 'select name, email users state="' $state '" order zip asc limit 5'; try instead using double quotes (") allow string substitution:
$query = "select name, email users state='$state' order zip asc limit 5"; or if want concatenation of values in string reason:
$query = "select name, email users state='" . $state . "' order zip asc limit 5"; another thought if still have issues utilize prepared statement method; never know if state needs filtered or not. seek this.
$query = "select name, email us__users state=? order zip asc limit 5"; $stmt = $mysqli->prepare($query); $stmt->bind_param('s', $state); $result = $stmt->execute(); $stmt->close(); while ($row = $result->fetch_array()) { print ($row['name'] . ' ' . $row['email']); } $result->free(); php mysql sql mysqli
No comments:
Post a Comment