473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to get the check box value using POST method in PHP ?

karthik baskar
I have a check box for which a user can check many values . I need to get the value of the check box in a variable in PHP to insert it into the database . Please someone help me ..
Nov 3 '10 #1
3 3388
a checkbox can't have many value, it's ON or OFF. In php you don't receive unchecked checkbox.
exemple
Expand|Select|Wrap|Line Numbers
  1. Cat <input type="checkbox" name="pet[]" value="cat">
  2. Dog <input type="checkbox" name="pet[]" value="dog">
  3. Pig <input type="checkbox" name="pet[]" value="pig">
  4.  
you will get an array of checked box. for exemple, you check cat and pig, you'll get for print_r($pet);
Expand|Select|Wrap|Line Numbers
  1.       Array
  2. (
  3.     [0] => cat
  4.     [1] => pig
  5. )
Nov 3 '10 #2
there are different ways to play with checkboxes using php, see below code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. echo $_REQUEST['a']."<br />";
  4. echo $_REQUEST['b']."<br />";
  5.  
  6. echo print_r($_REQUEST['c'])."<br />";
  7.  
  8. ?>
Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post">
  2.   <input type="checkbox" name="a" value="a">
  3.   <input type="checkbox" name="b" value="b">
  4.   <input type="submit" name="Submit" value="Submit">
  5. </form>
or

Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post">
  2.   <input type="checkbox" name="c[]" value="c1">
  3.   <input type="checkbox" name="c[]" value="c2">
  4.   <input type="submit" name="Submit" value="Submit">
  5. </form>
Nov 3 '10 #3
Thanks a lot :)
Nov 25 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: FF | last post by:
Hello I would like send variable to php script from URL using POST method. Is possible do it ? ( <a href="xxx.php">) thanks for your help FF
3
by: eddie wang | last post by:
When I use the following to post my value, I got SQL like this: SELECT+A%2ECMPL%5FFIELD%5FID%2C+A%2ECMPL%5FFACILITY%. How to get the SELECT without those hex value. THanks. <FORM...
10
by: ramata | last post by:
This is really strange for me. I have a demo.asp page, that can't pass hidden value "mr progrramer" to itself using POST method. Only "mr" is passed. I created a second asp file demo1.asp and...
4
by: davidfahy | last post by:
Hi all How can I transfer user to another server using POST. The problem is that Server.Transfer (preserves form data) works just in current server. Response.Redirect - uses GET method. However...
4
by: Velhari | last post by:
Hi all, We all know in GET method upto 2048 characters can be appended into URL. In the Same way what is the limit of sending data to server by using POST Method. Why asking this question...
2
by: sandeepk84 | last post by:
hi all... am trying to send data from one web page to another using post method.. the code is in C#.it's given in the click event of a command button. like destinationfilename.aspx?parameters how...
5
by: Bob Bedford | last post by:
Hi all, I've to accept a file that is sent using a POST method. The file will be sent using this URL: http://username:pass@www.mysite.com/upload.php How can I retrieve the username and...
2
by: ajmerasunny | last post by:
Hi, I have following task to implement: I have to pass username and password from first html page to second html page using POST Method and automatically submit the second html page on loading....
9
by: magix | last post by:
If I have <form action="process.asp" method="get" name="form1"> .... .... <input TYPE=checkbox name=sports VALUE=Cricket> <input TYPE=checkbox name=sports VALUE=Swimming> <input...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.