PDO PHP Query Syntax

Posted on 2014-08-24
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

    Spelling mistake

    ':deduictible_factor' => $mst
    LVL 107

    Assisted Solution

    by:Ray Paseur
    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now