0

嘿,我正在尝试使用此隐藏表单传递 xml 值:

<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 比较陌生,所以任何帮助将不胜感激谢谢

4

2 回答 2

1

execute如果您打算以这种方式使用,则不需要使用bindParam(反之亦然)。您确实需要将数组作为 key => value 传递,并将键作为查询中使用的符号(“符号”是从 Ruby 术语中借用的)。

于 2012-05-02T13:42:07.177 回答
0

您在execute方法中传递参数并将它们绑定到语句bindParam- 您只需要做一个或另一个!

于 2012-05-02T13:53:26.673 回答