ransy23 Posted October 9, 2008 Share Posted October 9, 2008 I am having trouble updating multiple rows in a MySQL database using PHP. (I can update single records, but not several rows at the same time.) When I click "Submit" nothing is updated. Any idea why? <?php //Connect to DB require_once('external_setup.php'); mysql_select_db($database, $db_connect); //Build and issue query $qry_result = mysql_query("SELECT * FROM fdic WHERE name = 'Kingston National Bank'") or die(mysql_error()); // Count table rows $count=mysql_num_rows($qry_result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>City</strong></td> <td align="center"><strong>Zip</strong></td> </tr> <?php while($rows=mysql_fetch_array($qry_result)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td> <td align="center"><input name="city[]" type="text" id="city" value="<? echo $rows['city']; ?>"></td> <td align="center"><input name="zip[]" type="text" id="zip" value="<? echo $rows['zip']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE fdic SET name='$name[$i]', city='$city[$i]', zip='$zip[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple2.php"); } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/127753-problem-updating-multiple-rows-in-mysql-using-php/ Share on other sites More sharing options...
DarkWater Posted October 9, 2008 Share Posted October 9, 2008 That's because you're checking for $Submit, which is NOT set. You'd need to explicitly use $_POST['Submit'] or set $_POST['Submit'] to a variable. Link to comment https://forums.phpfreaks.com/topic/127753-problem-updating-multiple-rows-in-mysql-using-php/#findComment-661174 Share on other sites More sharing options...
Chicken Little Posted October 9, 2008 Share Posted October 9, 2008 The form action is submit and I think the submit button code is different, something like this if (isset($_POST['Submit'])) Link to comment https://forums.phpfreaks.com/topic/127753-problem-updating-multiple-rows-in-mysql-using-php/#findComment-661181 Share on other sites More sharing options...
ransy23 Posted October 9, 2008 Author Share Posted October 9, 2008 I replaced this: // Check if button name "Submit" is active, do this if($Submit){ With this: // Check if button name "Submit" is active, do this if($_POST['Submit']){ It is still not working. I really appreciate the help. Link to comment https://forums.phpfreaks.com/topic/127753-problem-updating-multiple-rows-in-mysql-using-php/#findComment-661211 Share on other sites More sharing options...
Andy-H Posted October 9, 2008 Share Posted October 9, 2008 That script is seriously f****d up.... Link to comment https://forums.phpfreaks.com/topic/127753-problem-updating-multiple-rows-in-mysql-using-php/#findComment-661223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.