致命错误:在第17行的C:\ xampp \ htdocs esults.php中的非对象上调用成员函数escapeString()

Error:

Fatal error: Call to a member function escapeString() on a non-object in C:\xampp\htdocsesults.php on line 17

Line 17:

$searchterm=$db->escapeString($_GET['searchterm']);

It is called in mysql.php

public function escapeString($value){

return mysql_escape_string($value);

}

I am using MySQL on localhost.

Your $db variable is not set correctly. It's likely that the connection failed or something else went wrong.

Do this on the line right before 17:

var_dump($db); exit;

Chances are it will be null or false or some other non-object value indicating that the connection failed. To help more, we'd need to know more about what database connection you're attempting to make (mysql, mysqli, PDO, etc).

This will help you avoid errors:

if ( is_object($db) && isset($_GET['searchterm']) ) {
  $searchterm=$db->escapeString($_GET['searchterm']);
}

We will need more code if you're having problems setting one of the above items.