gpt4 book ai didi

php - 字符串中的元素数量与绑定(bind)变量的数量不匹配

转载 作者:行者123 更新时间:2023-11-28 23:52:43 24 4
gpt4 key购买 nike

// prepare and bind

你好,

我在尝试通过准备好的语句执行查询时收到以下错误:

Number of elements in string doesn't match number of bind variables     

代码如下:

$track = $con->prepare("INSERT INTO resources_record (name,email,stage,format,topic,max_cost,mentor,total_cost,duration)
VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?')");
$track->bind_param($fullName, $email, $stage, $format, $topic, $cost, $mentor, $price, $duration);

// Execute
$track->execute();

$track->close();

最佳答案

这里有两个明显的错误:

  • 不要在准备好的语句中的占位符周围加上引号
  • bind_param() 的第一个参数应该是一个字符串,用于标识后续参数的数据类型 - PHP Docs

$track = $con->prepare("INSERT INTO resources_record (name,email,stage,format,topic,max_cost,mentor,total_cost,duration)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$track->bind_param('sssssssss', $fullName, $email, $stage, $format, $topic, $cost, $mentor, $price, $duration);

一个由9个组成的字符串,因为你有9个参数,而且都是字符串()值

关于php - 字符串中的元素数量与绑定(bind)变量的数量不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32373914/

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