本文介紹了mysqli_stmt_bind_param():變量數與綁定參數中準備好的語句中的參數數不匹配的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我收到此錯誤.我想注冊到頁面.mysqli_stmt_bind_param():變量數與綁定參數中準備好的語句中的參數數不匹配.`
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>.
", mysqli_stmt_error($stmt));
}
$result = mysqli_stmt_get_result($stmt);
}
}
else { ?>`
推薦答案
在你的插入中,有 8 列,只有 7 個綁定
In your insert, are 8 columns and only 7 binds
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
The binds, is missing one, propably the 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()
,像這樣:
the numbers of s, columns and variables must be the same, in this case 8. To fix just add one s
and $salt
at bind_param()
, like this:
mysqli_stmt_bind_param($stmt, 'ssssssss', $fname, $lname, $password, $email, $bio, $location, $industry, $salt) or die("bind param");
這篇關于mysqli_stmt_bind_param():變量數與綁定參數中準備好的語句中的參數數不匹配的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!