Want to get checkbox name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foekall
    New Member
    • Jan 2007
    • 28

    Want to get checkbox name

    Dar all.....
    I want to get Check box name in php
    my code sample is here.....


    if(isset($_POST['delete'])
    {
    in this place.... How can i get checkbox name????
    can i get checkbox name which the user checked??

    }
    <html>
    <form method=POST>
    <?php
    $query=mysql_qu ery("SELECT id FROM table");
    while($result=m ysql_fetch_arra y($query))
    {
    echo "<input type=checkbox name={$result['id']} >
    }
    <input type=submit name=delete>

    ?>
    </form>
    </html>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You should know by now that your must enclose any shown code within php or code tags!
    Read the Posting Guidelines before you show any more code here!

    As for your question: you cannot do it like this in PHP. A checkbox is a client object and cannot be interrogated (DOM-wise) with PHP.

    The usual way to handle checkboxes is to give the box a name (or an array name) and let the values be filled by the MySQL result values. After submission you interrogate the POSTed name field or array and extract the values from it. Like the following sample shows:

    [php]<?php
    if (isset($_POST['submit'])) {
    print_r($_POST['checkit']);
    exit;
    }
    ?>
    <form method="POST" action="a.php">
    <input type="checkbox" name="checkit[]" value="1" />
    <input type="checkbox" name="checkit[]" value="2" />
    <input type="checkbox" name="checkit[]" value="3" />
    <input type="submit" name="submit" value="Submit" />
    </form>[/php]

    Ronald :cool:

    Comment

    • foekall
      New Member
      • Jan 2007
      • 28

      #3
      Originally posted by ronverdonk
      You should know by now that your must enclose any shown code within php or code tags!
      Read the Posting Guidelines before you show any more code here!

      As for your question: you cannot do it like this in PHP. A checkbox is a client object and cannot be interrogated (DOM-wise) with PHP.

      The usual way to handle checkboxes is to give the box a name (or an array name) and let the values be filled by the MySQL result values. After submission you interrogate the POSTed name field or array and extract the values from it. Like the following sample shows:

      [php]<?php
      if (isset($_POST['submit'])) {
      print_r($_POST['checkit']);
      exit;
      }
      ?>
      <form method="POST" action="a.php">
      <input type="checkbox" name="checkit[]" value="1" />
      <input type="checkbox" name="checkit[]" value="2" />
      <input type="checkbox" name="checkit[]" value="3" />
      <input type="submit" name="submit" value="Submit" />
      </form>[/php]

      Ronald :cool:
      many thz bro.........

      Comment

      Working...