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

 

 

Link to comment
Share on other sites

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' ");

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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);

 

?>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.