dongyoucha0645 2016-12-28 11:07
浏览 19
已采纳

php类型def与bind params不匹配

I have a table with 5 columns where the first column is a primary key and has a Auto_INCREMENT attribute. I am trying to insert a row into the table using the following code:

    <?php 

include "DBConstants.php";

$db = new DBConstants();

$connection = new mysqli($db->SERVER_NAME,$db->DB_USERNAME,$db->DB_PASSWORD,$db->DB_NAME);
$query = "INSERT INTO mailinglist (email, validationID, usRequest, isValidated) VALUES (?,?,?,?)";

$statement = $connection->prepare($query);

$email = $_GET["email"];
$validationID = openssl_random_pseudo_bytes ( 10, $crstrong);
$usRequest=false;
$isValidated = false;

$statement->bind_param($email,$validationID,$usRequest,$isValidated);
$statement->execute();

$statement->close();
$connection->close();

$array = array("result"=>true,"message"=>"You have successfully subscribed");
echo json_encode($array);

?>

But I am getting a warning like this:

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables

And hence the table is not being updated. Where am I going wrong?

  • 写回答

1条回答 默认 最新

  • drhzn3911 2016-12-28 11:16
    关注

    The first parameter of bind_param should be type of corresponding bind variables.

    $statement->bind_param('sisi', $email, $validationID, $usRequest, $isValidated);
    

    Note: Change the types in first param based on your data type.

    Reference Link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题