<?php$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "MyDB";//Create connection $conn = new mysqli ($servername, $username, $password, $dbname);//Detect connection if ($conn->connect_error) {die ("Connection failed:". $conn->connect_error);} Prepare and bind$stmt = $conn->prepare ("INSERT into Myguests VALUES (?,?,?)"); $stmt->bind_param ("SSS", $firstname, $lastname, $email);//Set parameters and Execute $firstname = "John"; $lastname = "Doe"; $email = "[ Email protected] "; $stmt->execute (); $firstname =" Mary "; $lastname =" Moe "; $email =" [email protected] "; $stmt Execute (); $firstname = "Julie"; $lastname = "Dooley"; $email = "[email protected]"; $stmt->execute (); echo "New Records Created successfully "; $stmt->close (); $conn->close ();? >
Run Times Error:
Bind_param () on a non-object
Reason:
The second argument to Bind_param is the one that is passed by reference.
Written directly to the string, which is not allowed in PHP 5.3 and later
Workaround:
$stmt = $conn->prepare ("INSERT into Myguests VALUES (?,?,?)");
Change to $stmt = $conn->prepare ("INSERT into Myguests (firstname, LastName, email) VALUES (?,?,?)");
When PHP writes to the database, call to a member function Bind_param () on a non-object