sg1psychopath Posted May 16, 2008 Share Posted May 16, 2008 I have a strange problem with part of my code. I have a loop that displays buttons in a form that should post to a different page. On the first time through the loop, the button returns to the same page (dlist.php), but during the other times, the button does as it should (posts to dedit.php). Here is the relevant bit of code (sorry, it's not that neat). for ($i=1; $row = mysql_fetch_array($choiceresult); $i++) { echo '<tr> <td>'.$i.'</td> <td>'.$row[1].'</td> <td>'.$row[2].'</td> <td>'.$row[4].'</td>'; if ($row[3] == 0) { echo '<td>   </td> <td>No</td>'; } else { echo '<td>'.$row[5].'</td> <td>Yes</td>'; } echo '<form action="dedit.php" method="post"><input type="hidden" name="editid" value="'.$row[0].'" /> <td><input type="submit" value="Edit" /></td> </form> </tr>'; } If you can help, thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/ Share on other sites More sharing options...
MadTechie Posted May 16, 2008 Share Posted May 16, 2008 try this <?php $i=1; while($row = mysql_fetch_array($choiceresult)) { $i++ echo '<tr> <td>'.$i.'</td> <td>'.$row[1].'</td> <td>'.$row[2].'</td> <td>'.$row[4].'</td>'; if ($row[3] == 0) { echo '<td>   </td> <td>No</td>'; } else { echo '<td>'.$row[5].'</td> <td>Yes</td>'; } echo '<form action="dedit.php" method="post"><input type="hidden" name="editid" value="'.$row[0].'" /> <td><input type="submit" value="Edit" /></td> </form> </tr>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/#findComment-542708 Share on other sites More sharing options...
sg1psychopath Posted May 16, 2008 Author Share Posted May 16, 2008 Unfortunately that didn't work. Thanks for trying though. Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/#findComment-542710 Share on other sites More sharing options...
MadTechie Posted May 16, 2008 Share Posted May 16, 2008 after re-reading your first post.. the code has nothing to do with dlist.php so i don't see how the problem could be their! Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/#findComment-542711 Share on other sites More sharing options...
sg1psychopath Posted May 16, 2008 Author Share Posted May 16, 2008 Sorry I'm not quite sure what you mean. I can post the rest of the code if you like, but I don't believe it has anything to do with the form or the problem. I've checked the page it posts to (dedit.php) but there is no way it could return to the dlist.php page, and even if it did, surely then it would do that every iteration of the loop? Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/#findComment-542714 Share on other sites More sharing options...
sg1psychopath Posted May 16, 2008 Author Share Posted May 16, 2008 You gave me an idea, and as usual it's made me look like a complete idiot! I forgot to close a <form> tag further up the code, and so it had to do one loop to close it, and then another to start doing what I thought it should have been doing. Thanks for the help though. Sorry for being a complete and utter dimwit! Quote Link to comment https://forums.phpfreaks.com/topic/105906-solved-form-button-not-working-first-time-through-loop/#findComment-542715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.