提问人:irjawais 提问时间:5/4/2016 最后编辑:irjawais 更新时间:5/4/2016 访问量:329
mysqli_stmt_bind_param(): 变量数与绑定参数中预准备语句中的参数数不匹配
mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in bind param
问:
我收到此错误。我想注册到页面。mysqli_stmt_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 { ?>`
答:
1赞
rray
5/4/2016
#1
在您的插入中,有 8 列,只有 7 个绑定
1 2 3 4 5 6
INSERT INTO user(first_name, last_name, email, password, bio, location,
7 8
industry,salt)
VALUES(?,?,?,?,?,?,?,?)
1 2 3 4 5 6 7 8
绑定,缺少一个,可能是salt
1234567
mysqli_stmt_bind_param($stmt, 'sssssss',
1 2 3 4 5 6 7
$fname, $lname, $password, $email, $bio, $location, $industry) or die("bind param");
S、列和变量的数量必须相同,在本例中为 8。要修复,只需添加一个,并在 ,如下所示:s
$salt
bind_param()
mysqli_stmt_bind_param($stmt, 'ssssssss', $fname, $lname, $password, $email, $bio, $location, $industry, $salt) or die("bind param");
评论
0赞
irjawais
5/4/2016
我必须加一招??
0赞
rray
5/4/2016
@user6251750 nedd 添加 1,并且 、 列和变量的数量必须相同,在本例中为 8。s
$salt
s
评论
?
mysql_bind_param(...)