0
 echo "<form action='recent.php' method='post' enctype='multipart/form-data'>";
        echo "<table id='logs' border='1' cellspacing='0' width='62%'>";
        echo "<tr>";
        echo "<th width='15%'>Time Logged</th>";
        echo "<th width='15%'>Username</th>";
        echo "<th width='15%'>Password</th>";
        echo "<th width='15%'>IP Address</th>";
        echo "<th width='2%'><a href=\"#\" onclick=\"checkAll(this);\">Mark</a></th>";
        echo "<th width='2%'>Delete</th>";

        echo "</tr>";
        while ($row = mysql_fetch_row($result))
        {
            echo "<tr>";
            echo ("<p><td>$row[2]</td><td>$row[0]</td><td>$row[1]</td><td><i>$row[3]</i></td><td><center><input type=\"checkbox\" name=\"mark[]\" value=\"$row[0]\" id=\"$row[0]\"></center></td><td><a href=\"delete.php?time=$row[2]&user=$row[0]&pass=$row[1]&ip=$row[3]\"><center>[x]</center></a></td></p>");
            echo "</tr>";
        }
        echo "</table>";
        echo "</form>";

The checkbox <input type=\"checkbox\" name=\"mark[]\" value=\"$row[0]\" id=\"$row[0]\"> Then I have

if ($_GET['mark']) {
            foreach ($_GET['mark'] as $mark) {
                echo "<li>$mark</li>";
            }
        }

But it doesn't show any checked checkboxes. And I also tried putting <input type="submit"> before the closing </form> and it still didn't echo results. What am I doing wrong?

3 Answers 3

4

Your form is POSTed but you're looking in $_GET.

3
  • what do you mean checked attribute?
    – Kyle
    Mar 30, 2011 at 19:49
  • He means your form method = POST, and you are looking the in the $_GET superglobal. You need to look in $_POST.
    – rayman86
    Mar 30, 2011 at 19:52
  • Ignore my previous answer, I've edited it now, I thought you were trying to show the input as checked from the start. Then I understood your question and found your problem. Mar 30, 2011 at 19:52
0

A lot of your HTML is just bad markup.

This is wrong <p><td></td></p> It should be <td><p></p></td> And <center></center> tags are deprecated.

<input type="checkbox" value="value" name="name" checked />
4
  • why downvoted? he is right. May not solve the problem but does not mean he does not have a point.
    – rayman86
    Mar 30, 2011 at 19:55
  • @rayman86: If it doesn't solve the problem, it shouldn't be posted as an Answer. That's what comments are for.
    – drudge
    Mar 30, 2011 at 20:01
  • if I had the reputation to comment I would. Mar 30, 2011 at 20:52
  • actually I just earned enough reputation to comment outside of my own answers Mar 30, 2011 at 20:57
0

Well, unless there's some new php syntax I haven't heard of (which is quite possible), don't you have to jump out of the string to use PHP variables? Like this:

echo "<li>".$mark."</li>";

If that's true, you have the same problem in your top script.

3
  • No, not with double-quoted strings or the heredoc syntax. Mar 30, 2011 at 19:51
  • PHP code echoed with double quotes does not need to be jumped out of to echo variables. PHP will automatically plug the variable values in a double quote string where it sees them. Single quote ones will have to be jumped out to get the value, however. See php.net/manual/en/language.types.string.php
    – rayman86
    Mar 30, 2011 at 19:51
  • Not necessary when using double-quotes.
    – drudge
    Mar 30, 2011 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.