2014-02-25 141 views
0
<?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"); 
?> 

我收到以下錯誤:未捕獲的異常 'PDOException' 有消息「SQLSTATE [HY093]:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in C:\xampp\htdocs\recordmanagement\main\reg.php:15 Stack trace: #0 C:\xampp\htdocs\recordmanagement\main\reg.php(15): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\recordmanagement\main\reg.php on line 15

在代碼中,我還不能確定這些值的含義:

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

我從源代碼下載它,所以它不是由我寫的。

+1

@Alex K.爲什麼這個問題變成了社區wiki? – jpw

+1

這個問題變成了一個社區wiki,因爲審稿人和提出修改的人都沒有做他們應該做的事。在帖子變得足夠好之前,它花了12次修訂,這應該只用1次完成。一篇帖子在10次修訂後成爲社區wiki。 –

+0

@JeroenVannevel我明白了。我不知道經過一定的修改後,帖子變成了維基。感謝澄清。 – jpw

回答

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字段中沒有匹配值。

不管這是因爲你在數值中缺少一個項還是它不需要,我不能說。

+0

非常感謝! :)你能告訴我這個代碼的含義是什麼? (:sas,:asas,:asafs,:offff,:statttt,:dot,:rd)「; – user3350719

+0

@ user3350719我認爲它們只是佔位符,用於指示在執行過程中應使用哪些數據替換哪些項目 – jpw

+0

我看到...順便說一句,非常感謝。我仍然有一個錯誤... – user3350719

相關問題