Question

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?

Was it helpful?

Solution

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

OTHER TIPS

The tokens are the part of the SQL query that are replaced from values passed to the function that executes the query (which, in this case are passed in an array); the error message says there are more tokens than values that should replace them.

The gist of it is that you have a prepared statement you are trying to execute, but you are not supplying one of the parameters needed.

But that's about all the information I can give you without seeing the actual query and calling code.

Its working for one page and not working on other one.

What did you find when you compared those two pages usage of update_coach_details()? Could they have different number of parameters, as suggested by this error:

Invalid parameter number: number of bound variables does not  match number of tokens
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top