【发布时间】:2018-10-15 02:33:00
【问题描述】:
我正在尝试使用准备好的语句进行查询。 代码如下
<?php
$studentrollno=1;
$studentclass=10;
$studentsection='A';
$host="localhost";
$dbName="school_election_db"
$conn=new mysqli_connect($host,dbName);
if(conn->connect_error())
{
echo "error occured";
}
else
{
$stmt="SELECT * FROM voting_details where studentrollno=? and
studentclass=? and studentsection=?";
$conn->bind_param($studentrollno,$studentclass,$studentsection);
$result=$conn->execute();
if(result==true)
{
echo "login succesfull";
}
else
{
echo "Please try again";
}
?>
错误与 mysqli 查询有关,但我无法找出错误。当我将普通语句与程序 PHP 一起使用时,它可以正常工作。但我读到正常的方法是使用 OOP 和准备好的语句. 我得到的错误是“mysqli_bind_param():: The number of elements in the statement does not match the number of bound parameters”。
【问题讨论】:
-
将
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);添加到脚本顶部。 -
您在此处列出的代码充满了语法错误。您可能希望显示给出错误的确切代码。
-
我不知道你是怎么得到这个错误的。您应该收到该代码的解析错误。
-
您的代码有很多语法错误。我们应该假设这只是错误的复制粘贴吗?
-
我已经编辑了所有内容..我希望现在一切都是正确的