[英]How can I solve this php / mysql error?
我的名字叫安娜,我刚开始用html css javascript php和mysql编程。 我希望将表单发送到数据库,但是每次尝试出现此错误时,都会出现:
警告:PDOStatement :: execute():SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与第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";
}
?>
删除这些行:
$stmt->bindValue(7, $fgenre, PDO::PARAM_STR);
$stmt->bindValue(8, $fdesc, PDO::PARAM_STR);
$stmt->bindValue(9, $fweb, PDO::PARAM_STR);
并在第六次绑定之后添加以下行:
$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);
在准备语句中计算问号。 它们是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
您忘记添加$stmt->bindValue(7, $fprovince, PDO::PARAM_STR)
,语句中缺少该列的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.