0

hey i'm attempting to pass xml values using this hidden form:

<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'>";

and insert the values in to mysql database using the PDO process:

 $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 ));

however i keep getting this error message when i attempt to use the form

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

I'm relatively new to using PDO so any help would be appreciated thanks

2
  • Try removing the space between $stmt and ->bindParam. May 2, 2012 at 13:13
  • I didn't try PDO much yet, but aren't you supposed to bindParam() or pass the values with the array in execute() ?
    – Kep
    May 2, 2012 at 13:16

2 Answers 2

1

You don't need to use execute if you're going to use bindParam in such a way (and vice versa). You do need to pass the array as key => value with the keys as the symbols used in the query ("symbol" being borrowed from Ruby terminology).

0

You're passing the parameters in both the execute method and binding them to the statment with bindParam - you only need to do one or the other!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.