0

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?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 1
    Please don't use `mysql_*` functions anymore, they are deprecated. See [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for details. Instead you should learn about [prepared statements](http://bobby-tables.com/php.html) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide which, [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you. If you pick PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – Marcel Korpel Nov 03 '13 at 21:06
  • 1
    BTW, you're vulnerable to SQL injections at the moment. – Marcel Korpel Nov 03 '13 at 21:07

2 Answers2

2

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

puelo
  • 5,464
  • 2
  • 34
  • 62
0

You have closeds SQL You need to remove mysql_close($con);

Shane
  • 244
  • 1
  • 4
  • 17