0

I have two tables:

table1- id, col1, col2, col3, col4, col5

id is an auto_increment.

table2- id, col1, col2, col3

In this, id is also Auto_increment and primary key on (col1,col2,col3).

My HTML form has some inputs; upon submit button click, I insert some inputs into table1 and the remaining inputs into table2. But the ids of these do not match. How can I ensure that the id of each newly inserted record is the same between the tables?

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Pratibha
  • 1
  • 1
  • Nope! But when I am inserting this record.It is not on diffrent time..query fire line by line..so. – Pratibha Mar 14 '15 at 18:13
  • What do you mean by "not on different time"? If you have a matching reference in all tables, say for userA, with username "BOB", you insert all his data with colum `username = BOB`, then to get all userA data, select on all tables where `username = BOB`. (Usernames, address etc are just examples. I'm not writing your code for you, just showing you the way) – James Mar 14 '15 at 18:15
  • Ok so I can check near primary set that I have used right. – Pratibha Mar 14 '15 at 18:18
  • 1
    I completely rewrote your title and summary paragraph to explain your apparent problem. I also added some useful tags to increase visibility and edited the intro some to clarify the problem somewhat. – Nathan Tuggy Mar 14 '15 at 21:25
  • Try foreign key instead - check solutions there: http://stackoverflow.com/questions/3544322/how-to-use-an-auto-incremented-primary-key-as-a-foreign-key-as-well – shudder Mar 14 '15 at 22:30
  • Please provide `SHOW CREATE TABLE` for each table, and a sample query that attempts to do your task. – Rick James Mar 15 '15 at 04:46

0 Answers0