gpt4 book ai didi

php - 使用两个变量在 Mysqli 中准备语句

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:16 25 4
gpt4 key购买 nike

我试图在 prepare 语句中传递我的两个变量,实际上我不能传递两个变量,我的代码有一个错误:

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /Applications/XAMPP/xamppfiles/htdocs/admin/genre.php on line 4

Fatal error: Call to a member function close() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/admin/genre.php on line 9

这是我的代码:

    <?php
include("../db_inc.php");
if($stmt=$connection->prepare("INSERT INTO genre(genre_name,genre_desc) VALUES('?','?')")){
$stmt->bind_param('sd',$genre_name,$genre_desc);
$genre_name =$_POST["genre_name"];
$genre_desc =$_POST['genre_desc'];
$stmt -> execute();
$stmt -> close();
$mysqli -> close();
}
$result=mysql_query($qry) or die(mysql_error());
if("$result"){
echo "Add Successfully";
}
?>

最佳答案

尝试从值中删除引号...

"INSERT INTO genre(genre_name,genre_desc) VALUES('?','?')"

应该是……

"INSERT INTO genre(genre_name,genre_desc) VALUES(?, ?)"

编辑-编辑:忘掉这个吧……我的观点是正确的

编辑:还有...

$stmt->bind_param('sd',$genre_name,$genre_desc);
$genre_name =$_POST["genre_name"];
$genre_desc =$_POST['genre_desc'];

应该是……

$genre_name =$_POST["genre_name"];
$genre_desc =$_POST['genre_desc'];
$stmt->bind_param('sd',$genre_name,$genre_desc);

您是在使用变量后对其进行声明。

关于php - 使用两个变量在 Mysqli 中准备语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19916576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com