[英]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.