I am getting this error.i wanna register to page. mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in bind param. `
<?php if(isset($_POST['submit'])) { // Was the form submitted?
$link = mysqli_connect("localhost", "root", "", "databaseInitialization") or die ("Connection Error " . mysqli_error($link));
$sql = "INSERT INTO user(first_name, last_name, email, password, bio, location, industry,salt) VALUES(?,?,?,?,?,?,?,?)";
if ($stmt = mysqli_prepare($link, $sql)) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$_SESSION['email'] = $email;
$bio = $_POST['bio'];
$location = $_POST['location'];
$industry = $_POST['industry'];
$salt = mt_rand();
$password = password_hash($salt.$_POST['pass'], PASSWORD_BCRYPT) or die("bind param");
//echo "before bind";
mysqli_stmt_bind_param($stmt, 'sssssss', $fname, $lname, $password, $email, $bio, $location, $industry) or die("bind param");
//echo "after bind";
if(mysqli_stmt_execute($stmt)) {
echo "<h4><b><center>Success</center></b></h4>";
//this redirects to user.php - but still need to log in
header('location: user.php');
} else {
echo "<h4><b><center>Failed</center></b></h4>";
printf("<b><center>Error: %s</center></b>.\n", mysqli_stmt_error($stmt));
}
$result = mysqli_stmt_get_result($stmt);
}
}
else { ?>`
In your insert, are 8 columns and only 7 binds
The binds, is missing one, propably the
salt
the numbers of s, columns and variables must be the same, in this case 8. To fix just add one
s
and$salt
atbind_param()
, like this: