<input type="checkbox" name="temp[0]" value="2352">
<input type="checkbox" name="temp[1]" value="47856">
<input type="checkbox" name="temp[2]" value="478">

When submitted this will create an array in PHP.  

This is the output of a test run

Array
(
    [0] => 3124
    [3] => 45
    [4] => 6756
)

Notice the indexes.

while (list ($key, $val) = each ($temp)) {
    echo "$key => $val<br />\n";
}

Charles

-----Original Message-----
From: Luis Moreira [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2003 9:31 AM
To: Charles P. Killmer
Subject: Re: [PHP-WIN] checkboxes in php


Must be whitout coffee, but don't see the point.
The passing of check boxes comes from the fact of selecting them or not.
I tried to insert your code and got nowere. How do you see if in between
those boxes, one in the middle is set ?

----- Original Message ----- 
From: "Charles P. Killmer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 10, 2003 3:12 PM
Subject: RE: [PHP-WIN] checkboxes in php


Try this

<?

    $i = 0;
    echo '<form>';
    echo '<input type="checkbox" name="temp['.$i++.']" value="3124">';
    echo '<input type="checkbox" name="temp['.$i++.']" value="6345">';
    echo '<input type="checkbox" name="temp['.$i++.']" value="456243">';
    echo '<input type="checkbox" name="temp['.$i++.']" value="45">';
    echo '<input type="checkbox" name="temp['.$i++.']" value="6756">';
    echo '<input type="checkbox" name="temp['.$i++.']" value="4567">';
    echo '<input type="submit" name="submit" value="test">';
    echo '</form>';


//Then in PHP whether the box is checked or not your indexes are
correct.

print_r($temp);
?>


Charles Killmer
Netgain Technology

-----Original Message-----
From: Luis Moreira [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2003 8:38 AM
To: Harpreet
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-WIN] checkboxes in php


Take this for an example :

This script fills part of a form with checkboxes named C1,C2, ect

   $cnt=0;
   for ($i=1;$i<=$n_alunos;$i++) {
    if ($cnt==0) {
     print "<tr>";
    }
    print "<td><input type=\"checkbox\" name=\"C$i\" value=\"on\">Aluno
$i</td>";
    $cnt++;
    if ($cnt==$colunas) {
     print "</tr>";
     $cnt=0;
    }
   }

This script receives the result from the previous form, and checks
wether checkbox C2 is set or not

if (!empty($_POST['C2'])) {
$b = $_POST['C2'];
}
else {
$b = "vazio";
}


An example ...

----- Original Message -----
From: "Harpreet" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 10, 2003 2:12 PM
Subject: [PHP-WIN] checkboxes in php


> I have 4 checkboxes in a form. I can select any number of boxes.When i

> go
to
> the results page it gives me errors for boxes i dont select
> Notice: Undefined index: toall in e:\INetPub... on line 27
>
> Please help
> Regards,
> Harpreet
>
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to