Re: Related Tables - Capture ID

From: Date: Thu, 26 Jun 2003 16:11:56 +0000
Subject: Re: Related Tables - Capture ID
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-28911@lists.php.net to get a copy of this message
$sql = "insert into table2(fld,fld2)values( 2, 4)"; $db->query($sql); $new_id = $db->query('select last_insert_id'); $sql = "insert into table3(table2_id, fld) values($new_id,3)" $db->query($sql); the altenative syntax for the secound query could also be $sql = "insert into table3(table2_id, fld) values(last_insert_id() ,3)" hop it helps Pete Marie Osypian wrote:
Hello, I have three table in which I am inserting records into in one script. I need to capture the ID of the second tables record insertion to insert into a field into a related table in the third. What would the easiest way to go about this in php? Thanks, MAO


« previous php.db (#28911) next »