Jump to content

[SOLVED] Form button not working first time through loop.


sg1psychopath

Recommended Posts

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> &nbsp </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!

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> &nbsp </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>';
        }
?>

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?

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!  ::)

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.