0

I'm extremely dumbfounded. What is the problem? I've copied over the default PHP OOS from http://www.php.net/manual/en/mysqli-stmt.bind-param.php and it keeps throwing errors.

<?php
$mysqli = new mysqli('localhost', 'root', 'hidden', 'hidden');

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$stmt = $mysqli->prepare("INSERT INTO users VALUES (?, ?)");
$stmt->bind_param('ss', $name, $password);

$name = "Test";
$password = "Test";

/* execute prepared statement */
$stmt->execute();

printf("%d Row inserted.\n", $stmt->affected_rows);

/* close statement and connection */
$stmt->close();

/* close connection */
$mysqli->close();
?>

Fatal error: Call to a member function bind_param() on a non-object in C:\xampp\htdocs\cms\index.php on line 11

1 Answers1

0

change these lines : (as u insert 2 string parameters into users table)

$stmt = $mysqli->prepare("INSERT INTO users VALUES (?, ?)");
$stmt->bind_param('sssd', $name, $password);

with : (i assume that u have to insert name and password fields... if not, use ur appropriate fields name for name and password)

if (!($stmt = $mysqli->prepare("INSERT INTO users(name,password) VALUES (?, ?)"))) {
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$stmt->bind_param('ss', $name, $password);
Suhel Meman
  • 3,702
  • 1
  • 18
  • 26