Jump to content

Insert into 2 MS access tables from 1 form?


dh526

Recommended Posts

Firstly, thank you for looking ! :)

 

Now for the question, is it possible to enter details from a form into 2 Access tables at once?

 

This is the sort of thing I want to do :

<form method="post" action="register.php">


<table border = 0>

<tr>
<td>Username: </td> <td> <input type="text" name="username" /></td> <td> Please choose a unique username </td>
</tr>


<tr>
<td>Forename: </td> <td> <input type="text" name="forename" /></td>
</tr>

<tr> 
<td>Surname: </td> <td> <input type="text" name="surname" /> </td> 
</tr>

<tr>
<td>DOB: </td> <td> <input type="text" name="dob" /> </td> <td>Please enter in the form of dd/mm/yyyy</td>
</tr>

<tr>
<td>Email: </td> <td> <input type="text" name="email" /> </td>
</tr>

<tr>
<td><br></td>
</tr>

<tr>
<td>House Number: </td> <td> <input type="text" name="housenumber" /> </td>
</tr>

<tr>
<td>Street: </td> <td> <input type="text" name="street" /> </td>
</tr>

<tr>
<td>Town: </td> <td> <input type="text" name="town" /> </td>
</tr>

<tr>
<td>Postcode: </td> <td> <input type="text" name="postcode" /> </td><td> enter in the form of LL99 9LL </td>
</tr>

<tr>
<td> <input type="submit"></td> <td>  </td>
</tr>


</form>
</table>

 

and the php file:

 

<?php

$username= $_POST ['username'];
$surname = $_POST ['surname'];
$forename = $_POST ['forename'];
$dob = $_POST ['dob'];
$email = $_POST ['email'];
$housenumber =  $_POST ['housenumber'];
$street = $_POST ['street'];
$town = $_POST ['town'];
$postcode =  $_POST ['postcode'];

$conn=odbc_connect('db09','','');

$sql="INSERT INTO tblCustomer (username, Surname, Forename, DOB, [Email Address]) VALUES 

('$username', '$surname','$forename', '$dob','$email')";

$sql2="INSERT INTO tblAddress (username, HouseNumber, Street, Town, Postcode) VALUES ('$username', '$housenumber','$street', '$town','$postcode')";



if (odbc_exec($conn,$sql,$sql2)) {
echo "Welcome, Your records have been added to our system";
}

odbc_close($conn);

?>

 

Is this possible?? Or not?

 

Thank you for looking :)

 

I only worked with mysql until yet, but you could try:

$sql="INSERT INTO tblCustomer (username, Surname, Forename, DOB, [Email Address]) VALUES 
('$username', '$surname','$forename', '$dob','$email');";

$sql.="INSERT INTO tblAddress (username, HouseNumber, Street, Town, Postcode) VALUES ('$username', '$housenumber','$street', '$town','$postcode')";

if (odbc_exec($conn,$sql)...

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.