Select last insert id

前端 未结 2 1209
無奈伤痛
無奈伤痛 2020-12-06 07:58

I am inserting a record and i want to use the id of the last record inserted. This is what i have tried:

    $sql = 
    \'INSERT INTO customer
(first_name,
         


        
相关标签:
2条回答
  • 2020-12-06 08:34

    You can do another query:

    $last_id = "SELECT LAST_INSERT_ID()";

    Or try to add ; in your query:

    INSERT INTO customer (first_name, last_name, email, password, date_created, dob, gender, customer_type) VALUES(:first_name, :last_name, :email, :password, :date_created, :dob, :gender, :customer_type)<b>;</b>' . ' SELECT LAST_INSERT_ID()';

    0 讨论(0)
  • 2020-12-06 08:43

    Check out mysql_insert_id()

    mysql_query($sql);
    $id = mysql_insert_id();
    

    When that function is run after you've executed your INSERT statement in a mysql_query() command its result will be the ID of the row that was just created.

    0 讨论(0)
提交回复
热议问题