Kyle
Kyle

Reputation: 3042

Not echoing checked checkboxes

 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?

Upvotes: 0

Views: 94

Answers (3)

linus72982
linus72982

Reputation: 1393

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.

Upvotes: 0

Chris McClellan
Chris McClellan

Reputation: 1105

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 />

Upvotes: 0

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

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

Upvotes: 4

Related Questions