带有消息'SQLSTATE [HY093]的未捕获异常'PDOException':

时间:2014-02-25 10:38:47

标签: sql database

<?php
include('connect.php'); 
$date = $_POST['date'];
$student_ID = $_POST['student_ID'];
$full_name = $_POST['full_name'];
$year_section = $_POST['year_section'];
$payment_description = $_POST['payment_description'];
$amount = $_POST['amount'];
$received_by = $_POST['received_by'];

// query
$sql = "INSERT INTO transaction (date,student_ID,full_name,year_section,payment_description,amount,received_by) VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft)";
$q = $db->prepare($sql);
$q>execute(array(':sas'=>$date,':asas'=>$student_ID,':asafs'=>$full_name,':offff'=>$year_section,':statttt'=>$payment_description,':dot'=>$amount,':rd'=>$received_by));
header("location: index.php");
?>

我收到以下错误:

  

致命错误:带有消息'SQLSTATE [HY093]的未捕获异常'PDOException':参数号无效:绑定变量数   与令牌的数量不匹配   C:\ xampp \ htdocs \ recordmanagement \ main \ reg.php:15堆栈跟踪:#0   C:\ XAMPP \ htdocs中\ recordmanagement \主\ reg.php(15):   PDOStatement-&gt;执行(数组)#1 {main}抛出   第15行的C:\ xampp \ htdocs \ recordmanagement \ main \ reg.php

在代码中我也不确定这些值的含义:

 (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft);

我是从源代码下载的,所以它不是我写的。

1 个答案:

答案 0 :(得分:0)

查询中似乎有一个字段。这样:

$sql = "INSERT INTO transaction 
(date,student_ID,full_name,year_section,payment_description,amount,received_by) 
VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd,:ft)";

应该是:

$sql = "INSERT INTO transaction 
(date,student_ID,full_name,year_section,payment_description,amount,received_by) 
VALUES (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd)";

因为:ft字段没有匹配值。

这是因为你遗漏了价值中的一个项目,还是不需要它我不能说。