Search code examples
phpdoctrinedql

Uncaught exception: Invalid parameter number


I am firing an update query that works for one page, but not another.

Here's the output:

Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 
    'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' in
    C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Connection.php:1084
    Stack trace:
    #0 C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Connection\Statement.php(253): 
       Doctrine_Connection->rethrowException(Object(PDOException),         
       Object(Doctrine_Connection_Statement))
    #1 C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Connection.php(1049):      
       Doctrine_Connection_Statement->execute(Array)
    #2 C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Query\Abstract.php(1091):    
       Doctrine_Connection->exec('UPDATE users SE...', Array)
    #3 C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Query\Abstract.php(1142):   
       Doctrine_Query_Abstract->_execute(Array)
    #4 C:\xampp\htdocs\fanyer\doctrine\models\Users.php(122):
       Doctrine_Query_Abstract->execute()
    #5 C:\xampp\htdocs\fanyer\include\update_profile.inc.php(18):
       Users->update_coach_details('', '', NULL, 'Select', 'dav', 'coach', '3')
    #6 in C:\xampp\htdocs\fanyer\doctrine\lib\Doctrine\Connection.php on line 1084

Here's my code:

public function update_coach_details($fname,$lname,$city,$state,$school,$rights,$user_id)
{
    return Doctrine_Query::create()
        ->update('Users')   
        ->set('f_name', '?', $fname)
        ->set('l_name', '?', $lname)
        ->set('city', '?', $city)
        ->set('state', '?', $state)
        ->set('school', '?', $school)
        ->set('rights', '?', $rights)
        ->where("id = '$user_id'")
        ->execute();
}

$account_type=$_SESSION['rights'];
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$state= $_POST['state'];
$school= $_POST['school'];
$sports= $_POST['sports'];
$sports_array = explode(',',$sports);
$user_id=$_SESSION['user_id'];
$users= new Users();
$users->update_coach_details($fname,$lname,$city,$state,$school,$account_type,$user_id);

Is the problem caused by my passed parameters?


Solution

  • Looks like you are passing undefined variable $city to update_coach_details. Try to add something like $city = '' before function call.