Web Analytics Made Easy -
StatCounter php mysql checkboxes NEEDhelp .... - CodingForum

Announcement

Collapse
No announcement yet.

php mysql checkboxes NEEDhelp ....

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • php mysql checkboxes NEEDhelp ....

    hey i got this script who list all entries from a database to a html table like here:
    PHP Code:
    <?php
    $result 
    mysql_query("SELECT * FROM test")
    or die(
    mysql_error());  
    ?><form method="post" action="test.php">
    <table border="1">
    <tr><td>check</td><td>id</td><td>name</td><td>pass</td></tr>
    <?php
    while($row mysql_fetch_array$result )){

    ?>

    <tr>
    <td><input type="checkbox" style="text-align:center;" name="cheked" value="<?php echo $row['id']; ?>"></td>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['name']; ?></td>
    <td><?php echo $row['pass']; ?></td>
    </tr>



    <?php

    }
    ?>

    </table>
    <input type="submit" value="go">
    </form>
    and now on the second page i want to get the values of all the checked boxes so i can do something with them E.g delete them or so ... i tried this:
    PHP Code:
    <?php

    while($_POST['cheked']){
    $thing="checked" $doit;
    echo 
    $_POST['checked'];




    }


    ?>
    but i realized that just ****ed up .. :S so if any1 got something which can help me it would be great

    PS:if my server is on you can check it in action at Hmail.servegame.org/sql(i turned off the second page you submits to Because i dont want to **** your browser up. )

    THanks in advance
    Last edited by diload; Apr 14, 2009, 03:05 PM.

  • #2
    Untested, but try the below.

    1. Change the first line of your form to the below, to make the checked name an array. Note [] brackest being used.

    PHP Code:
    <td><input type="checkbox" style="text-align:center;" name="checked[]" value="<?php echo $row['id']; ?>"></td>
    2. When processing the form, loop through the array and do something with its value.

    PHP Code:
    $selected $_POST['checked'];

    foreach (
    $selected as $value)
    {
        echo 
    'The id selected is: ' $value;

    Comment


    • #3
      it worked thank you verey much!

      Comment

      Working...
      X