Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    working with checkboxes

    I have the following code
    Code:
    	<td width = '2%' height="40"> <div align="center"><input type="checkbox" name="checkbox[]" value="<?PHP $rows['player_number']; ?>"></div></td>
    on one page

    then on the second page I have


    PHP Code:
    <?php
      $aDoor 
    $_POST['checkbox'];
      if(empty(
    $aDoor))
      {
        echo(
    "You didn't select any buildings.");
      }
      else
      {
        
    $N count($aDoor);
        echo(
    "You selected $N door(s): ");
        for(
    $i=0$i $N$i++)
        {
          echo(
    $aDoor[$i] . " ");
        }
      }
      
      foreach (
    $aDoor as $statename)
    {
        
    echo 
    "$statename is checked";
    }

    if(
    $aDoor){
        foreach(
    $aDoor AS $sID => $sValue){
            
    //Here you can process each posted value separately
            
    echo "Checkbox with value ".$sValue." was checked!<br>";
        }
    }

    foreach(
    $_POST['checkbox']  as  $value)  {
     
     echo 
    "Checked: $value\n";

     
    }

        
        if(!empty(
    $_POST['checkbox'])){

            for (
    $i=0$i count($_POST['checkbox']);$i++) {

                   echo 
    $_POST['checkbox'][$i] . ", ";

            }

    }

    foreach ( ( array ) 
    $_POST['checkbox'] as $value )

    {

        
    // do whatever the crap you want with $value

        
    echo $value;




    if (
    count($_POST) > 0) { 
    echo 
    '<pre>'print_r($_POST); echo '</pre>';
    }

    if(isset(
    $_POST['submit'])) 
        { 
        
    $compare $_POST["checkbox"]; 
        echo 
    '<h2>Checkbox values:</h2>'
        foreach (
    $compare as $value
            echo 
    $value."<br />"
        } 
        

     
    ?>
    The problem I have is that I can't see what is passed with each checkbox. I have tried to the examples in the php code and nothing seems to work. Can you help me with figuring out this problem?

    I am using a while loop so there is a chance I could have 1 row or 100 rows. I click the checkbox and then send to the second page. I can't see the values on the second page.

  • #2
    New Coder
    Join Date
    Feb 2008
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    I don't know what I did...but it is fixed now with the following code

    Code:
    name="checkbox[]" value="<?PHP echo $rows['player_number']; ?>"></div></td>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •