Reputation:
I am trying to use one form to insert data into 2 tables.
I have one table, Members and another, Members.
Here is my code:
<?php
$first_name=$_POST[first_name];
$last_name=$_POST[last_name];
$email_address=$_POST[email_address];
$staff=$_POST[staff];
$type=$_POST[type];
$descr=$_POST[descr];
$time=$_POST[time];
mysql_select_db("cl49-vogclients", $con); $sql="INSERT INTO member
(first_name,last_name,email_address)
VALUES
('$first_name','$last_name','$email_address')";
if (!mysql_query($sql,$con)) { die('Error adding client ' . mysql_error()); } mysql_close($con);
echo' <h2><font color="green">Client Added Succesfuly</font> </h2>';
$sql1="INSERT INTO audit
(staff,type,descr)
VALUES
('$staff','$type','$descr')";
if (!mysql_query($sql1,$con)) { die('Audit Unsucsessful ' . mysql_error()); } mysql_close($con);
echo' <h2><font color="green">Audit Succesful</font> </h2>';
This adds the client/member but not add anything to the audit database?
Upvotes: 0
Views: 100
Reputation: 5977
This is because you are only executing the first query:
mysql_query($sql,$con)
You have to call it seperatly for $sql1
Besides that: Please bear in mind that mysql like this is heavily outdated and deprecated. You should really look into PDO and prepared statements. http://php.net/manual/de/book.pdo.php
Upvotes: 2