Hi All,
I am having a hard time getting SQL transactions to work in PHP. I am using the following code in my form's process.php file and I am being redirected to the success.html page but when I check the database, there is no data being written to the tables. If I remove the transaction and just insert to one table everything works fine. Any help will be much appreciated. Thanks in advance:
I am having a hard time getting SQL transactions to work in PHP. I am using the following code in my form's process.php file and I am being redirected to the success.html page but when I check the database, there is no data being written to the tables. If I remove the transaction and just insert to one table everything works fine. Any help will be much appreciated. Thanks in advance:
Code:
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
$DiscrepType = mysql_prep($_POST['List1']);
$DiscrepDetail = mysql_prep($_POST['List2']);
$Airdate = $_POST['Airdate'];
$Description = mysql_prep($_POST['Description']);
$Resolution = mysql_prep($_POST['Resolution']);
$OnAirVariance = mysql_prep($_POST['OnAirVariance']);
$EquipID = mysql_prep($_POST['EquipID']);
$EquipLoc = mysql_prep($_POST['EquipLoc']);
$StartTime = $_POST['StartTime'];
$EndTime = $_POST['EndTime'];
$MaterialID = $_POST['MaterialID'];
$Title = $_POST['Title'];
?>
<?php
$query = BEGIN;
"INSERT INTO tblonairactivity (
DiscrepType, DiscrepDetail, Airdate, Description, Resolution, OnAirVariance, EquipID, EquipLoc
) VALUES (
'{$DiscrepType}', '{$DiscrepDetail}', '{$Airdate}', '{$Description}', '{$Resolution}', '{$OnAirVariance}', '{$EquipID}', '{$EquipLoc}'
)";
"INSERT INTO tblaffectedprog (
StartTime, EndTime, MaterialID, Title
) VALUES (
'{$StartTime}', '{$EndTime}', '{$MaterialID}', '{$Title}'
)";
COMMIT;
$result = mysql_query($query, $connection);
if ($result) {
// Success!
redirect_to("success.html");
} else {
// Display error message.
echo "<p>Record creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
?>
<?php mysql_close($connection); ?>