Jump to content

[SOLVED] post script mysql help


lux00r

Recommended Posts

i have a form posting data to 1 tablein a db, inside the first db table i will be asigning aunique row id to the form data. then inside the samepost script i will be inserting the data into moretables, how would i assign the unqiue id assigned inthe first db insertion to the remaining db tables?

Link to comment
https://forums.phpfreaks.com/topic/48694-solved-post-script-mysql-help/
Share on other sites

i know how to set the auto_increment id for the first table, i need to use that generated id for subsequent different table inserts during the same post script.

 

for example:

 

form data -> post script -> table 1 insert (id assigned) -> table 2 insert (take id assigned in table 1) .

 

I need to connect 4 different tables using the id generated

 

 

Just use the same variable name in the subsequent insert statements....

$value="TEST";

$select1=mysql_query("SELECT * FROM table1 WHERE value='$value' ");

$select2=mysql_query("SELECT * FROM table2 WHERE value='$value' ");

$select3=mysql_query("SELECT * FROM table3 WHERE value='$value' ");

i understand your concept of using the same value = test.

 

 

However, would it be possible to use the id value that is created during the first table insert auto increment function, which is handled by mysql db.

 

 

form data ->  post script -> table 1 insert (id created with auto_increment column) -> table 2 insert (use the id created from table 1)

i found the solution:

 

<?php

$account_query="INSERT INTO accounts (account_id,type) VALUES (NULL,'saving')";

$transaction_query="INSERT INTO transactions(transaction_id,account_id) VALUES (NULL,LAST_INSERT_ID)" ;

 

$a_query=mysql_query($account_query);

$t_query=mysql_query($transaction_query);

 

?>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.