Petsmacker Posted January 11, 2007 Share Posted January 11, 2007 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. Link to comment https://forums.phpfreaks.com/topic/33809-quick-update-of-multiple-rows-using-looping-arrays-noob-problem/ Share on other sites More sharing options...
Petsmacker Posted January 12, 2007 Author Share Posted January 12, 2007 Having to Bump. Sorry!!Really need help with this one. Link to comment https://forums.phpfreaks.com/topic/33809-quick-update-of-multiple-rows-using-looping-arrays-noob-problem/#findComment-158920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.