If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Last Insert Id

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-20-05, 17:16
homchz homchz is offline
Registered User
 
Join Date: Jan 2004
Posts: 45
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
Reply With Quote
  #2 (permalink)  
Old 11-20-05, 19:06
homchz homchz is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 11-21-05, 10:11
jfulton jfulton is offline
Registered User
 
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() ?
Reply With Quote
  #4 (permalink)  
Old 11-21-05, 12:16
homchz homchz is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On