Hello Everybody,
I wish to update many records in a InnoDB table, using the Rollback feature.
The only why i can see to do it, is using 'variable variables', but i cant figure it out.
Anyone know how to do this...?
<?php # SHOW PAGE +++++++++++
$qD="SELECT recordid,name,age FROM table_people WHERE dept='accounts'";
$rD=mysql_query($qD, $conDB) or die(mysql_error()." Q=".$qD); $numrowsD=mysql_num_rows($rD);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="MyForm" id="MyForm">
<table border="0" cellpadding="0" cellspacing="0" id="Tmain">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><input name="Bupdate" type="submit" id="Bupdate" value="Update" /></td>
<td> </td>
<td> </td>
</tr>
<?php mysql_data_seek($rD,0); while ($rowD=mysql_fetch_array($rD)): extract($rowD); ?>
<tr>
<td>id:
<input name="recordid[]" type="text" id="recordid[]" value="<?php echo $recordid; ?>" size="4" maxlength="4" /></td>
<td>Name:</td>
<td colspan="2"><input name="name[]" type="text" id="name[]" value="<?php echo $name; ?>" size="35" maxlength="30" /></td>
<td>Age:</td>
<td><input name="age[]" type="text" id="age[]" value="<?php echo $age; ?>" size="4" maxlength="2" /></td>
</tr>
<?php endwhile; ?>
</table>
</form>
<?php
# PROCESS FORM ++++++++++++++
if (isset($_POST['Bupdate'])):
for ($i=0; $i<count($_POST['recordid']); $i++):
$q="UPDATE table_people SET name='".$_POST['name'][$i]."', age='".$_POST['age'][$i]."' WHERE recordid='".$_POST['recordid'][$i]."'";
endfor;
endif;
?>
<?php
# PROCESS FORM + FAILSAFE +++++
if (isset($_POST['Bupdate'])):
mysql_query("START TRANSACTION");
$q1="UPDATE table_people SET name='".$_POST['name1']."', age='".$_POST['age1']."' WHERE recordid='".$_POST['recordid1']."'";
$r1=mysql_query($q1, $conDB) or die(mysql_error()." Q=".$q1);
$q2="UPDATE table_people SET name='".$_POST['name2']."', age='".$_POST['age2']."' WHERE recordid='".$_POST['recordid2']."'";
$r2=mysql_query($q2, $conDB) or die(mysql_error()." Q=".$q2);
$rGO=mysql_query("COMMIT"); # Rollback only works if different names for 'r'
endif;
?>
The only way i can get ROLLBACK to work properly is to have different assignments for each 'mysql_query', so how can i combine the two...
<?php
if (isset($_POST['Bupdate'])):
mysql_query("START TRANSACTION");
for ($i=0; $i<count($_POST['recordid']); $i++):
$q="UPDATE table_people SET name='".$_POST['name'][$i]."', age='".$_POST['age'][$i]."' WHERE recordid='".$_POST['recordid'][$i]."'";
$r.$i=mysql_query($q, $conDB) or die(mysql_error()." Q=".$q); # errors
$$r=mysql_query($q, $conDB) or die(mysql_error()." Q=".$q); # errors
endfor;
$rGO=mysql_query("COMMIT");
endif;
?>