PDO PHP Query Syntax

Posted on 2014-08-24
Medium Priority
Last Modified: 2014-09-09
I'm getting the following error from this update query and I can't figure it out.  I know it is simple but I can't see it:
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined - line 59?  at the very end.

	if (empty($errors)) { // If everything's OK.

		//  Test for unique 

		$q = $pdo->prepare("SELECT deductible_id FROM wp_bicycle_physical_damage WHERE deductible_id = :id");

		$q->bindParam(':id', $id, PDO::PARAM_STR);


		try	{

			$q->execute(array(':id' => $id));	


			$result = $q->fetchAll();

			if($result) {


			// Make the query to update:

			$newsr = $pdo->prepare("UPDATE wp_bicycle_physical_damage

			SET deductible = :deductible,

			deductible_factor = :deductible_factor

			WHERE deductible_id = :id

			LIMIT 1");


			$newsr->bindParam(':id', $id, PDO::PARAM_STR);

			$newsr->bindParam(':deductible', $st, PDO::PARAM_STR);

			$newsr->bindParam(':deductible_factor', $mst, PDO::PARAM_STR);



			try	{


				':id' => $id,

				':deductible' => $st,

				':deduictible_factor' => $mst


Open in new window

Question by:rgranlund
LVL 58

Accepted Solution

Gary earned 1000 total points
ID: 40281980
Spelling mistake

':deduictible_factor' => $mst
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 40282098
Looking at these statements, I am led to believe that you can write cleaner and more dependable code if you use variables names that correlate to the column names.
$newsr->bindParam(':id',                $id,  PDO::PARAM_STR);
$newsr->bindParam(':deductible',        $st,  PDO::PARAM_STR);
$newsr->bindParam(':deductible_factor', $mst, PDO::PARAM_STR);

Open in new window

If, for example, $st was $deductible (and similar for $mst) the parallel construction would lead you in the direction of more straightforward automation with less repetition of the variable and column names.  It might help to reduce the frequency of spelling and typographical errors.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question