我的名字是Anna,我刚刚开始用html、css、javascript、php和mysql进行编程。我希望将我的表单发送到我的数据库,但是每次我尝试这个错误时,都会显示:
警告: PDOStatement::execute():SQLSTATEHY093:无效的参数号:绑定变量的数量与第38行/var/www/send_festival.php中的标记数不匹配
我知道这意味着什么,但我找不到哪里出了问题。有谁能告诉我去哪里找吗?“
提前谢谢!
代码:
<?php
include("opendb.php");
function generate_salt() {
$fh=fopen('/dev/urandom','rb');
$random=fgets($fh,16);
fclose($fh);
return $random;
}
$fname = $_POST["fname"];
$forgan = $_POST["forgan"];
$fbegin = $_POST["fbegin"];
$fend = $_POST["fend"];
$floc = $_POST["floc"];
$fprov = $_POST["fprov"];
$fprice = $_POST["fprice"];
$fgenre = $_POST["fgenre"];
$fdesc = $_POST["fdesc"];
$fweb = $_POST["fweb"];
$success = false;
try {
$stmt = $db->prepare('INSERT INTO Festivals (festival_name, festival_organisator, festival_begin, festival_end, festival_location, festival_province, festival_priceregular, festival_genre, festival_description, festival_website) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->bindValue(1, $fname, PDO::PARAM_STR);
$stmt->bindValue(2, $forgan, PDO::PARAM_STR);
$stmt->bindValue(3, $fbegin, PDO::PARAM_STR);
$stmt->bindValue(4, $fend, PDO::PARAM_STR);
$stmt->bindValue(5, $floc, PDO::PARAM_STR);
$stmt->bindValue(6, $fprice, PDO::PARAM_STR);
$stmt->bindValue(7, $fgenre, PDO::PARAM_STR);
$stmt->bindValue(8, $fdesc, PDO::PARAM_STR);
$stmt->bindValue(9, $fweb, PDO::PARAM_STR);
$status = $stmt->execute();
if ($status) {
header('Location: /add_festival.php?success=true');
}
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>发布于 2015-01-15 13:58:33
删除这些行:
$stmt->bindValue(7, $fgenre, PDO::PARAM_STR);
$stmt->bindValue(8, $fdesc, PDO::PARAM_STR);
$stmt->bindValue(9, $fweb, PDO::PARAM_STR);并在第6次装订后添加行如下:
$stmt->bindValue(7, $fprov, PDO::PARAM_STR);
$stmt->bindValue(8, $fgenre, PDO::PARAM_STR);
$stmt->bindValue(9, $fdesc, PDO::PARAM_STR);
$stmt->bindValue(10, $fweb, PDO::PARAM_STR);发布于 2015-01-15 14:02:52
在准备陈述中数一下你的问号。它们是10,所以您需要绑定10个变量,但您只绑定了9个变量。
$stmt->bindValue(1, $fname, PDO::PARAM_STR); //festival_name
$stmt->bindValue(2, $forgan, PDO::PARAM_STR); //festival_organisator
$stmt->bindValue(3, $fbegin, PDO::PARAM_STR); //festival_begin
$stmt->bindValue(4, $fend, PDO::PARAM_STR); //festival_end
$stmt->bindValue(5, $floc, PDO::PARAM_STR); //festival_location
$stmt->bindValue(6, $fprice, PDO::PARAM_STR); //festival_province
$stmt->bindValue(7, $fgenre, PDO::PARAM_STR); //festival_priceregular
$stmt->bindValue(8, $fdesc, PDO::PARAM_STR); //festival_genre
$stmt->bindValue(9, $fweb, PDO::PARAM_STR); //festival_description
???? //festival_website发布于 2015-01-15 14:00:03
您忘记添加一个$stmt->bindValue(7, $fprovince, PDO::PARAM_STR),语句中缺少该列的值。
https://stackoverflow.com/questions/27964842
复制相似问题