I have a form that is used to insert 34 rows into one mysql table. I need some trick that will back out all of the inserts if any one has an error.
Here is my current insert code:
As it is currently, it will insert rows until it hits an error and then stop. I need it to undo all the previous inserts if there are any errors.
Here is my current insert code:
Code:
$rownumber = 34;
$count = 1;
while ($count <= $rownumber) {
$firstname = $_POST["firstname-$count"];
$lastname = $_POST["lastname-$count"];
$writetable = "name_list";
$writefields = "name_list_firstname, name_list_lastname";
$writevalues = "'$firstname','$lastname'";
$sql="INSERT INTO $writetable ($writefields)
VALUES
($writevalues)";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
print ("Record $count entered");
print ("<br />");
$count = ++$count;
}
As it is currently, it will insert rows until it hits an error and then stop. I need it to undo all the previous inserts if there are any errors.