-1
我正在嘗試使用PDO/PHP來顯示數據並將數據插入到使用MySQL的數據庫中。代碼的顯示部件工作正常,但每當我嘗試插入數據我得到這個錯誤:在PDO/PHP代碼中的未知錯誤
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
這裏是我的代碼:
<?php
$number = 1;
include 'connection.php';
try {
$conec = new Connection();
$con = $conec -> Open();
if ($con) {
$sql1 = "SELECT company_name FROM test_corp WHERE company_num = $number";
$stmt1 = $con->query($sql1);
$row = $stmt1->fetchObject();
$company_name = $row->company_name;
if (isset($company_name)) {
} else {
echo "error: memory location not set.";
}
$sql2 = "SELECT company_abb FROM test_corp WHERE company_num = $number";
$stmt2 = $con->query($sql2);
$row = $stmt2->fetchObject();
$company_abb = $row->company_abb;
if (isset($company_abb)) {
} else {
echo "error: memory location not set.";
}
$sql3 = "SELECT company_price FROM test_corp WHERE company_num = $number";
$stmt3 = $con->query($sql3);
$row = $stmt3->fetchObject();
$company_price = $row->company_price;
if (isset($company_price)) {
} else {
echo "error: memory location not set.";
}
$sql4 = "SELECT investor_username FROM test_corp WHERE company_num = $number";
$stmt4 = $con->query($sql4);
$row = $stmt4->fetchObject();
$Sample_Investor1 = $row->investor_username;
if (isset($Sample_Investor1)) {
} else {
echo "error: memory location not set.";
}
$sql5 = "SELECT investor_amount FROM test_corp WHERE company_num = $number";
$stmt5 = $con->query($sql5);
$row = $stmt5->fetchObject();
$Sample_Investor1_Amount = $row->investor_amount;
if (isset($Sample_Investor1_Amount)) {
} else {
echo "error: memory location not set.";
}
if (isset($_POST['Buy_Dollar'])) {
$Buy_Dollar = $_POST['Buy_Dollar'];
}
$total = 100;
$query7 = "INSERT INTO test_corp (company_name, company_abb,company_price, investor_name, investor_username, investor_amount, total, company_num) VALUES (:insert_value1, :insert_value2,:insert_value3, :insert_value4, :insert_value5, :insert_value6, :insert_value7, insert_value8)";
$stmt7 = $con->prepare($query7);
$stmt7->bindParam(':insert_value1', $company_name);
$stmt7->bindParam(':insert_value2', $company_abb);
$stmt7->bindParam(':insert_value3', $company_price);
$stmt7->bindParam(':insert_value4', $investor_name);
$stmt7->bindParam(':insert_value5', $investor_username);
$stmt7->bindParam(':insert_value6', $Buy_Dollar);
$stmt7->bindParam(':insert_value7', $total);
$stmt7->bindParam(':insert_value8', $number);
$stmt7->execute();
} else {
echo $con;
}
}
catch (PDOException $ex) {
echo $ex -> getMessage();
}
?>
你是什麼意思不明錯誤? –
缺少一些東西 - >'insert_value8)' –
'insert_value8'有一個冒號缺失。它應該是':insert_value8' –