Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.