check boxes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
call
Forum Newbie
Posts: 10
Joined: Thu Mar 18, 2004 12:15 am
Location: india

check boxes

Post by call »

In asp or coldfusion, when I submit a list of check boxes to action page, I am able to get the values of all the check boxs with a comma(,) delimiter. But the same is not happening with php? What are the reasons for that?
User avatar
bawla
Forum Contributor
Posts: 116
Joined: Fri Mar 19, 2004 9:15 am

Post by bawla »

wut does your script look like?
call
Forum Newbie
Posts: 10
Joined: Thu Mar 18, 2004 12:15 am
Location: india

Post by call »

page.htm

===

<form name="form1" method="post" action="form2.php">
<input type="checkbox" name="linc" value="1">1
<input type="checkbox" name="linc" value="2">2
<input type="checkbox" name="linc" value="3">3
<input type="checkbox" name="linc" value="4">4
<input type="checkbox" name="linc" value="5">5

<input type="submit" value="submit" name="somename">

</form>

=======
page2.php
=========

<?

echo $_POST['linc'];

?>



the page2.php is showing only one value if we check more then one value
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

of course it will only show one value

a. you dont have an array to arrange multiple variables if multiple variables are checked
b. seeing u dont have an array, you have name = linc for all your inputs, hence making only one variables regardless.

try.

Code: Select all

<?php
<form action=form2.php?$linc method=POST>
<input type=checkbox name=linc[] value="1">1 
<input type=checkbox name=linc[] value="2">2 
<input type=checkbox name=linc[] value="3">3 
<input type=checkbox name=linc[] value="4">4 
<input type=checkbox name=linc[] value="5">5 
</form>

// form2.php

if (isset($linc)) {
// here use a foreach or while loop to display all your array info, i'm not going to write that for you
}
?>
I think that will do the trick
Post Reply