Jump to content

Quick Update of Multiple Rows Using Looping Arrays. Noob problem.


Petsmacker

Recommended Posts

I'm trying to get multiple rows in my database to update using a loop. I send the info through this form:

[code]<form method="POST" style="margin-bottom:0;" action="staffinfo.php?do=updateallinfo">
<?php
$result9998=mysql_query("SELECT * FROM staff_info");
$num9998=mysql_numrows($result9998);
$i=0;$no="1";
while ($i < $num9998) {
$si_id=mysql_result($result9998,$i,"id");
$si_name=mysql_result($result9998,$i,"name");
$si_info=mysql_result($result9998,$i,"info");
$si_order=mysql_result($result9998,$i,"order");
?>
<tr>
<td valign="top"><center><input type="text" name="si_name<?echo "$no"; ?>" size="10" maxlength="20" value="<?echo "$si_name"; ?>"></center></td>
<td valign="top"><center><input type="text" name="si_order<?echo "$no"; ?>" size="2" maxlength="2" value="<?echo "$si_order"; ?>"></center></td>
<td><center><textarea name="si_info<?echo "$no"; ?>" cols=44 rows=6><?echo "$si_info"; ?></textarea></center></td>
</tr>
<?$no=$no+1;?>
<?++$i;}?>
</table><br><input type="submit" value="Submit"></form>[/code]


Then on the 'do=updateallinfo' page:
[code]
<?php
$r=1;
while ($r < $si_counttot){
$yourname=preg_replace("/(<[^>]+>)|[^\w-]+/","",$_POST['si_name$r']);
$yourinfo=trim(addslashes(strip_tags($_POST['si_info$r'])));
$yourorder=ereg("^[0-9]+$", $_POST['si_order$r']);
$updateit=mysql_query("UPDATE staff_info SET info='$yourinfo', name='$yourname', order='$yourorder' WHERE name='$yourname'");
++$r;}
header ("location: $ref");exit();?>[/code]

You may or may not see what I'm trying to do, I'm no good at working with arrays but I felt that in theory, this should work. It doesn't. If I echo '$_POST['si_name4'] for example, it does echo the correct value. However when I echo '$yourname' the value disappears - this is the case for the other variables too. Please help me, I don't know why the variables aren't passing to $yourname, $yourinfo and $yourorder.

Hope you can help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.