Adding ID in second Table I have two table one is photos and another one is photo_detail, this is how i have created both tables:

/* creating photos table */
CREATE TABLE photos(
-&gt;  pid INT(10) NOT NULL AUTO_INCREMENT,
-&gt;  purl VARCHAR(200) NOT NULL,
-&gt;  uid INT(5) NOT NULL,
-&gt;  time TIMESTAMP NOT NULL,
-&gt;  title VARCHAR(80) NOT NULL,
-&gt;  PRIMARY KEY (pid)
-&gt;  )
-&gt;  ENGINE = InnoDB DEFAULT CHARSET = utf8;

/* creating photo_detail table */

CREATE TABLE photodetail(
-&gt;  pid INT(6) NOT NULL,
-&gt;  ptext TEXT NOT NULL,
-&gt;  location VARCHAR(40) NOT NULL,
-&gt;  FOREIGN KEY (pid) REFERENCES photos(pid)
-&gt;  )
-&gt;  ENGINE = Innodb DEFAULT CHARSET = utf8;


My question is how i can add the automatically incremented ID from photos table to photo_detail table  while storing the photo? i am using PHP language! any suggestion on this table design?
You can use LAST_INSERT_ID() to get the inserted id for example if you insert a row in your photos table and you need that auto incremented id for the detail table you can do so

INSERT INTO photos (purl, uid,`time`,title)
VALUES ( 'test',1,1111,'test');
INSERT INTO photodetail (pid, ptext, location)
VALUES (LAST_INSERT_ID(), 'test', 'test');


Fiddle Demo