SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,096
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post lastinsertid problem

    Hi, Can you help me please on this, i want to get the last inserted id but it gives me on this error

    72SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
    Here is my code

    Code:
    function addCredit($a,$b){
    
        try{
    
            $con = new Connection();
            $dbh = $con->dbconnection();
    
            $dbq=$dbh->prepare('INSERT into credit (cr_x,cr_y) values (?,?)');
            $dbq->execute(array($a,$b));
    
            $id = $dbh->lastInsertId();
    
            echo $id;
    
            $dbh=null;
    
            return "Completed";
    
    
        }
    
        catch(PDOException $e){
            return $e->getMessage();
        }
    
    }

    Thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    I think it doesn't give the error on the line with the lastInsertId, but on the execution of the insert query itself.

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,096
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I think it doesn't give the error on the line with the lastInsertId, but on the execution of the insert query itself.

    Hi my insert statement is working i already tried to insert in my db,but the time when i want to get the lastinsertid,the error occurs...

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,096
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I think it doesn't give the error on the line with the lastInsertId, but on the execution of the insert query itself.

    Sorry my bad,...I apologize,..yes i got wrong parameter in other function that is why it throws error...

    Thank you for giving me this idea

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jemz View Post
    Sorry my bad,...I apologize,..yes i got wrong parameter in other function that is why it throws error...

    Thank you for giving me this idea
    You're welcome. I'm glad you solved your problem


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •