简体   繁体   English

mysqli_stmt :: bind_param()变量不匹配

[英]mysqli_stmt::bind_param() variable doesn't match

What's going wrong in this script it is giving me error for bind_param 这个脚本出了什么问题,这给我bind_param的错误

if(isset($_GET['ID'])){

$page_id = $_GET['ID'];

      $page_id = mysqli_real_escape_string($con, $page_id);



$select_query = $con->prepare("select * from save_data where ID='$page_id'")
    or die(mysqli_error($con)); 

$select_query->bind_param('i', $page_id);

$select_query->execute();

$result = $select_query->get_result();

Getting this error 得到这个错误

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in C:\\xampp\\htdocs\\mysql_login\\pictures.php on line 23 警告:mysqli_stmt :: bind_param():类型定义字符串中的元素数量与C:\\ xampp \\ htdocs \\ mysql_login \\ pictures.php中第23行的绑定变量数量不匹配

You are not using a placeholder in your query. 您没有在查询中使用占位符。 You inadvertently put the variable you wish to replace it with instead: 您无意间将要替换的变量放在了上面:

$select_query = $con->prepare("select * from save_data where ID='$page_id'")

should be: 应该:

$select_query = $con->prepare("select * from save_data where ID=?")

You want this instead of the line you have: 您想要这个而不是您拥有的行:

$select_query = $con->prepare("select * from save_data where ID=?");

In the code you posted you don't use parameter binding at all - you interpolate the variable directly into the SQL string. 在发布的代码中,您根本不使用参数绑定-您直接将变量插值到SQL字符串中。 For parameter binding you need to insert a ? 对于参数绑定,您需要插入一个? placeholder instead! 占位符代替!

Also, please don't use or die(mysqli_error($con) for debugging. That's extremely hacky. Either just let it fail with an exception (mysqli does have an option for this, right?) or write custom wrapper that handles error properly without requiring you repeat the same code every time you perform a query! 另外,请不要使用or die(mysqli_error($con)进行调试。这非常hacky。要么让它失败并抛出异常(mysqli对此有一个选项,对吗?)或编写可正确处理错误的自定义包装器无需每次执行查询时都重复相同的代码!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mysqli:mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不匹配 - Mysqli:mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement mysqli_stmt::bind_param() [mysqli-stmt.bind-param]:变量数量与参数数量不匹配 - mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters mysqli_stmt::bind_param()类型定义字符串中的元素个数与个数不匹配 - mysqli_stmt::bind_param()Number of elements in type definition string doesn't match number mysqli_stmt :: bind_param():变量数与准备好的语句中的参数数不匹配 - mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement mysqli_stmt :: bind_param():变量数量与php中准备好的语句中的参数数量不匹配 - mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in php mysqli_stmt :: bind_param变量数与准备好的语句中的参数数不匹配 - mysqli_stmt::bind_param Number of variables doesn't match number of parameters in prepared statement 警告:mysqli_stmt :: bind_param()变量数与准备好的语句中的参数数不匹配 - Warning: mysqli_stmt::bind_param() Number of variables doesn't match number of parameters in prepared statement MySQLi 警告:mysqli_stmt::bind_param():变量数与准备语句中的参数数不匹配 - MySQLi Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in mysqli_stmt :: bind_param():类型定义字符串中的元素数量与绑定变量数量不匹配 - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables warning mysqli_stmt::bind_param(): 类型定义字符串中的元素数与绑定变量数不匹配 - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM