Hello everyone i'm getting the following error message.
Fatal error: Call to a member function prepare() on a non-object in C:\xampplite\htdocs\Prepared_Statements.php on line 20
My code so far
connection.php
$db_server = "localhost";
$db_user = "root";
$db_password = "";
$db = "test";
$connection = mysql_connect($db_server,$db_user,$db_password,$db);
if(!$connection){
die("Database Connection Failed".mysql_error());
}
$select_database = mysql_select_db($db,$connection);
if(!$select_database){
die("Database selection failed".mysql_error());
}
Prepared_Statements.php
include_once("connection.php");
$name = "John";
$surname = "Smith";
$address = "London";
$number = 63.23;;
$query = "INSERT INTO books VALUES(?,?,?,?)";
$stmt = $db->prepare($query);
$stmt->bind_param("sssd",$name,$surname,$address,$number);//"sssd"= string,string,string and double
$stmt->execute();
echo $stmt->affected_rows.'Book inserted into rows';
$stmt->close();
Could you please suggest me a solution to this problem.
And im using PHP Version 5.3.1 with xampp
Thank you for your time