Solved

PHP - reading checkboxes

Posted on 2006-11-09
4
189 Views
Last Modified: 2008-03-17
Hi all,

I am having difficulty with reading the multiple check box array values from a form.

I have searched this forum and copied and pasted WORKING code but this did not work for me.

I have copied and pasted, a working copy of process from ===  http://www.smartwebby.com/PHP/Phptips2.asp

BUT this does not work for me.

Checkboex have exactly the same syntax as supposed working versions of similar scripts. But i cannot get it to work.


Any ideas,

Cheers
0
Comment
Question by:sydron
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:babuno5
ID: 17912200
whats the exact problem are u facing
0
 

Author Comment

by:sydron
ID: 17912226
well i dont get the results displayed at all...the string is empty

and i try to echo $count(thearray) and it gives me 0.....

am i missing something here?
0
 
LVL 15

Accepted Solution

by:
babuno5 earned 125 total points
ID: 17912257
<?php
print("<pre>");
print_r($_REQUEST);
$chkexpert = $_REQUEST['chkexpert'];
$hidSubmit = $_REQUEST['hidSubmit'];
$strExpert="";
if(isset($hidSubmit)){
$count=count($chkexpert);
for($i=0;$i<$count;$i++){$strExpert="$strExpert$chkexpert[$i], ";}
}
?>

<form name="form1" method="post" action=""> <table width="100%" border="0" bgcolor="#D6E3F7">
<tr>
<td class="text">Your are Expertise field: </td>
</tr>
<tr>
<td class="examplelink">
<input type="checkbox" name="chkexpert[]" value="Java">
Java
<input type="checkbox" name="chkexpert[]" value="PHP">
PHP
<input type="checkbox" name="chkexpert[]" value="ASP">
ASP
<input type="checkbox" name="chkexpert[]" value=".NET">
.NET
<input type="checkbox" name="chkexpert[]" value="JavaScript">
JavaScript</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit">
<input name="hidSubmit" type="hidden" id="hidSubmit2" value="true"></td>
</tr>
<tr>
<td class="subtitlesmall"><p>Result:</p>
<p><span class="reditalic">Your Expertise field: <?php echo $strExpert; ?></span></p></td>
</tr>
<tr>
<td class="reditalic">&nbsp; </td>
</tr>
</table>
</form>
0
 

Author Comment

by:sydron
ID: 17913169
Hi babuno5,

Thanks for your solution.

It worked.

Cheers,
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question