2012-05-02 169 views
0

嘿,我嘗試使用這個隱藏表單傳遞XML值:PHP的XML PDO插入查詢錯誤

<form method='post' action='addholiday.php' id='addHoliday'> 
<input type='hidden' name='title' id='title' value= '.$holiday->title'> 
<input type='hidden' name='link' id='link' value= '.$holiday->link'> 
<input type='hidden' name='date' id='date' value= '.$holiday->pudDate'> 
<input type='hidden' name='description' id='description' value= '.$holiday->description'> 
    <input type='submit' name='submit' value='Add Holiday'>"; 

,並使用PDO過程中插入值,以MySQL數據庫:

$db = getConnection(); 

//get holiday infor from hidden form 
$user = $_SESSION['user']; 
$title = $_POST['title']; 
$link = $_POST['link']; 
$date = $_POST['date']; 
$description = $_POST['description']; 

//insert the values in to favorties table 
$sql = "INSERT INTO saved_holidays (subscriberID, link, pubDate, title, description,dateSaved) 
VALUES (:subscriberID, :link, :pubDate, :title, :description, now())"; 

$stmt = $db->prepare($sql); 
$stmt ->bindParam(':subscriberID', $user); 
$stmt ->bindParam(':link', $link); 
$stmt ->bindParam(':pubDate',$date); 
$stmt ->bindParam(':title', $title); 
$stmt ->bindParam(':description', $description); 

$stmt->execute(array($user, $link, $date, $title, $description)); 

但我不斷收到此錯誤信息,當我嘗試使用該表格

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: 
Invalid parameter number: parameter was not defined' in  var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/addholiday .php:39 Stack trace: #0 
/var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11023553/public_html/holiday/addholiday.php(39):PDOStatement->execute(Array) #1 {main} thrown in /var/www/vhosts/numyspace.co 
.uk/web_users/home/~unn_w11023553/public_html/holiday/addholiday.php on line 39 

我比較新使用PDO,所以任何幫助將b e表示感謝

+0

嘗試刪除$ stmt'和''之間的空間 - > bindParam'。 –

+0

我沒有嘗試PDO的還不很多,但你不應該bindParam()** **或與陣列經過值的execute()? – ccKep

回答

1

如果您打算以這種方式使用bindParam(反之亦然),則不需要使用execute。您需要將鍵值作爲key =>值傳遞給查詢中使用的符號(「符號」是從Ruby術語中借用的)。

0

您在execute方法中傳遞參數並將它們與bindParam綁定在一起 - 您只需要做一個或另一個!