Jump to content

Is one SUBMIT into multiple tables possible?


Recommended Posts


I'm not sure if this belongs in the PHP or SQL sections or both but-

Is it possible to insert form data (one record) into 2  different tables when I click submit?

  As is, I have 2 distinct log-in scripts each linked to 2 separate databases .  I want to merge them into one log-in form that populates both tables(in different dbs). I don't want my visitors to log into 2 different forms.  Can one form's action attribute send the POST data to two different processing scripts? and can the input from a text  box be sent to 2 different fields?

I don't have any code, I just wanted to know if it can be done or point me to a sample that I can work from.



Link to comment
Share on other sites

So you want to have one form to interact with two different databases?


if(isset($_POST['submit'])) {
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
// etc

$con1 = mysql_connect("localhost", "root", "password", "db1") or die(mysql_error());
$con2 = mysql_connect("somewhere", "root", "password", "db2") or die(mysql_error());

mysql_query("INSERT INTO one (field1, field2) VALUES ($field1, $field2)", $con1) or die(mysql_error($con1));
mysql_query("INSERT INTO two (field1, field2) VALUES ($field1, $field2)", $con2) or die(mysql_error($con2));


Remember always to clean your inputs

Link to comment
Share on other sites

Yes, thanks.  And I was wondering if I can do this with the form:


<form action="mysql_insert.php" method="POST">
Firstname: <input type="text" name='field1','field2' />

<input type="submit" />

Seems like this should be possible.


-Your script being mysql_insert.php


i will try it out later



Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.