Php 字符串中的元素数不为';不匹配绑定变量的数量
嗨 尝试通过准备好的语句执行查询时,我收到以下错误:Php 字符串中的元素数不为';不匹配绑定变量的数量,php,mysql,sql,mysqli,Php,Mysql,Sql,Mysqli,嗨 尝试通过准备好的语句执行查询时,我收到以下错误: // prepare and bind 以下代码: Number of elements in string doesn't match number of bind variables 这里有两个明显的缺点: 不要在准备好的语句中的占位符周围加引号 bind_param()的第一个参数应该是一个字符串,用于标识后续参数的数据类型- 由9个s组成的字符串,因为您有9个参数,并且都是字符串(s)值不要在准备好的语句中的占位符
// prepare and bind
以下代码:
Number of elements in string doesn't match number of bind variables
这里有两个明显的缺点:
- 不要在准备好的语句中的占位符周围加引号
的第一个参数应该是一个字符串,用于标识后续参数的数据类型-bind_param()
由9个
s
组成的字符串,因为您有9个参数,并且都是字符串(s
)值不要在准备好的语句中的占位符周围加引号。bind_param()
的第一个参数应该是标识后续参数的数据类型的字符串-
$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();
$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);