Hello I want to insert data with a form in 2 different tables from my db. After I search a lot, I found about transactions s-o I have make the code:
<?php
// TRANZICTII
function begin()
{
@mysql_query("BEGIN");
}
function commit()
{
@mysql_query("COMMIT");
}
function rollback()
{
@mysql_query("ROLLBACK");
}
include("Connections/mysql_connnect.php");
$sql1="INSERT INTO texte (Cat, autorId, Titlu, Text) VALUES ('$_POST[Cat]','$_POST[autorId]','$_POST[Titlu]','$_POST[Text]')";
begin(); // incepe tranz
$result = @mysql_query($sql1);
if(!$result)
{
rollback(); // tranz rolls back
echo "you rolled back";
exit;
}
$sql2="INSERT INTO texte (Cat, autorId, Titlu, Text) VALUES ('$_POST[Cat]','$_POST[autorId]','$_POST[Titlu]','$_POST[Text]')";
begin(); // incepe tranz
$result = @mysql_query($sql2);
if(!$result)
{
rollback(); // tranz rolls back
echo "you rolled back";
exit;
}
else
{
commit(); // tranz is committed
echo "data is in!";
}
?>
I want to know if this code is good? or not and what do I need to insert now in the form page.
Thanks,
Vlad