Page 1 of 1

Multiple table insertion

Posted: Thu May 19, 2011 5:20 am
by batowiise
Hi All,

I want to keep audit of transactions. I have two tables, one acting as the main table and the other acting as a copy of the main table (audit) with some of the field copied to the audit table.

The following is my code but data is not been written to the audit table.

Your help is welcome

Code: Select all


$traveller = $_REQUEST['traveller'];
$requestdate = $_REQUEST['requestdate'];

require_once("../admin/db.php");

$sqlinsert="INSERT INTO `internationaltravel` (`traveller`,`requestdate`)
VALUES ('$traveller','$requestdate')";
				
mysql_query($sqlinsert);
				
$last_inserted_id = mysql_insert_id();
				
$sqlinsert_audit="INSERT INTO `audit` (`date`,`initiator`,`transid`)
				VALUES ('$requestdate','$traveller',$last_inserted_id)";

Re: Multiple table insertion

Posted: Thu May 19, 2011 7:49 am
by maneetpuri
Hi,

First try this,

replace this code

$sqlinsert_audit="INSERT INTO `audit` (`date`,`initiator`,`transid`)
VALUES ('$requestdate','$traveller',$last_inserted_id)";

With the below code (single quotes are missing for the IIIrd value)

$sqlinsert_audit="INSERT INTO `audit` (`date`,`initiator`,`transid`)
VALUES ('$requestdate','$traveller','$last_inserted_id')";

if above does not work then try this,-

Go to mysql query browser and execute the insert statement, if there are error in the insert statement it will show you the exact error.


Hope this helps,

Thanks,

Re: Multiple table insertion

Posted: Thu May 19, 2011 8:13 am
by batowiise
hi and thanks for your reply. the above solutions still did not work. please what next?

Re: Multiple table insertion

Posted: Thu May 19, 2011 8:46 am
by mikosiko
2 simple debugging actions:

a) as a temporary error control modify this line as it is shown

Code: Select all

             mysql_query($sqlinsert) or die("Query Error : " . mysql_error() . "<br /> SQL was : " . $sqlinsert);
b) same for the $sqlinsert_audit

and in your code you are not showing where are you executing $sqlinsert_audit... are you?

Re: Multiple table insertion

Posted: Sat May 21, 2011 5:51 pm
by emelianenko
batowiise wrote:hi and thanks for your reply. the above solutions still did not work. please what next?

can you echo your variables to make sure you have passed them from your form ?

and also, you are not using mysql_query to execute your query, all you do is put it into a variable, but what is happening next ?