刚开始学习php并遇到此问题。: mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不符
一切正常,我的数据保存到数据库中,我收到显示“注册成功”的消息,但仍然收到该错误消息。
此行显示错误
$stmt->bind_param("ssss", $firstname, $surname, $passwor, $email);
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$passwor = $_POST['passwor'];
$email = $_POST['email'];
if (!empty($firstname) || !empty($surname) || !empty($passwor) || !empty($email))
{
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "registration";
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error())
{
die ('Connect Error(' . mysqli_connect_errno().')'. mysqli_connect_error());
}
else
{
$SELECT = "SELECT email From loginas Where email = ? Limit 1";
$INSERT = "INSERT Into loginas (`firstname`, `surname`, `passwor`, `email`) values('$firstname', '$surname', '$passwor', '$email')";
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0)
{
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("ssss", $firstname, $surname, $passwor, $email);
$stmt->execute();
echo "Registartion sucesfull";
}
else
{
echo "This email is already in use";
}
$stmt->close();
$conn->close();
}
}
else {
echo "All fields must be filled";
die();
}
答案 0 :(得分:1)
您稍后将在您的代码中准备此语句并传递绑定的参数,因此对于您要绑定到它的每个参数,都需要用?
来编写
$INSERT = "INSERT Into loginas
(`firstname`, `surname`, `passwor`, `email`)
values(?,?,?,?)";