php xml PDO插入查询错误

时间:2012-05-02 13:01:20

标签: php forms pdo

嘿,我试图使用这个隐藏的表单传递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比较新,所以感谢任何帮助

2 个答案:

答案 0 :(得分:1)

如果您要以这种方式使用execute,则无需使用bindParam(反之亦然)。您需要将数组作为key =&gt;传递使用键作为查询中使用的符号的值(“符号”是从Ruby术语中借用的)。

答案 1 :(得分:0)

您在execute方法中传递参数并使用bindParam将它们绑定到参数 - 您只需要执行其中一项操作!