Results 1 to 4 of 4

Thread: Last Insert Id

  1. #1
    Join Date
    Jan 2004
    Posts
    45

    Unanswered: Last Insert Id

    I am trying to run three queries.

    Insert user
    Insert business with id from user
    Update user with id from business

    However I am getting no value on my second LAST_INSERT_ID() and no errors on my query

    Is there a limit to the number of time you can user LAST_INSERT_ID() in a row?

    Code:
    INSERT INTO $this->ad_table (username, password, user_email, last_log_time, location, user_group, date_created, time_zone, validation_id) 
    										 VALUES ('$uname', '$password', '$_POST[email]', $date, '$_POST[location]', '2', $date, '$_POST[timezone]', '1'
    Code:
    INSERT INTO $this->ad_table (user_id, contact_name, business_email, catagory, business_name, street_address, city, state, zip_code, 
    										  phone_number, fax_number, business_logo, logo_location, affiliate_bs_id, date_created, web_site) 
    										  VALUES (LAST_INSERT_ID(), '$_POST[b_contact]', '$_POST[b_email]', '$_POST[b_category]', '$_POST[b_name]', '$_POST[b_street]',
    										  '$_POST[b_city]', '$_POST[b_state]', '$_POST[b_zip]', '$_POST[b_phone]', '$_POST[b_fax]', '$file' , 'Uploads', '$_POST[b_store]', $date, '$_POST[b_web_site]'
    Code:
    UPDATE $this->ad_table SET store_id = 'LAST_INSERT_ID()' WHERE username = '$uname'
    all the variables are correct.

    Any Ideas?

    Josh

  2. #2
    Join Date
    Jan 2004
    Posts
    45
    I decided to pull a new query to select the last id instead.

    One more step but it works now.

    Though if anyone does know why this was not working any info would be great.

    Thanks,

    Josh

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    I'm assuming the value of $this->ad_table changes between these three calls?

    Why do you have single quotes around your second LAST_INSERT_ID() ?

  4. #4
    Join Date
    Jan 2004
    Posts
    45
    $this->ad_table does change.

    The '' is just somthign I was trying and forgot to take it out for my example. With or without it does not work on the last query.

Posting Permissions

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