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 > Index on 2 different tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-14-04, 15:32
Eroc Eroc is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Question Index on 2 different tables

I searched but I really don't know what I am searching for... but this is what I have...

I have two tables... 1 has an index the other doesn't...

when I insert into the one that has the index the index autoincrements... how do I grab that index number in the same insert (or not) so I can reference and insert it in the other table?

That make sense?

Thanks !
Eroc
Reply With Quote
  #2 (permalink)  
Old 08-15-04, 09:52
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
If some of your code is providing the values, you'll have to retrieve those yourself. If MySQL is providing them using AUTO_INCREMENT, then you can retrieve the value using LAST_INSERT_ID().

-PatP
Reply With Quote
  #3 (permalink)  
Old 08-15-04, 10:10
Eroc Eroc is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks for your reply and getting me started !!!

Here is what I have:

Code:
INSERT INTO phpbb_posts_text (post_id, post_subject, post_text) VALUES ( WHATHERE,'$subject', '$body')
The field is Auto_Increment(ed) and I even tried:

Code:
INSERT INTO phpbb_posts_text (post_subject, post_text) VALUES ( '$subject', '$body')
but I get: Error adding entry: Duplicate entry '0' for key 1

Can anyone offer any help?

thanks,
Eroc
Reply With Quote
  #4 (permalink)  
Old 08-16-04, 12:26
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Based on that error message, methinks thou need'st mysqlcheck.

-PatP
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