473,388 Members | 1,375 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,388 software developers and data experts.

Null value / non checked chexkbox value posting problem

19
Dear all,
I am fresh php programmer. I've spent much time to solve a checkbox related null value submission problem in php platform.

I want to submit 4 checkbox value. if I checked all the checkbox, all the checked value is submitted properly. if checked any checkbox , the corresponding checkbox value is submitted properly.

But I need to send the non checked value (please let non checked value is N ) with the checked checkbox value.

Please run the following php code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <title>checkbox help</title>
  5. </head>
  6. <?
  7.  
  8. if (isset($HTTP_POST_VARS)) {
  9.  
  10.         $fruit = $HTTP_POST_VARS["fruit"];
  11.  
  12.         echo("Fruits chosen: " . count($fruit) . "<br><br>");
  13.  
  14.         if (count($fruit)>0) {
  15.                 echo("You chose the following fruits:<br>");
  16.         }
  17.  
  18.         for ($i=0; $i<count($fruit); $i++) {
  19.                 echo( ($i+1) . ") " . $fruit[$i] . "<br>");
  20.         }
  21. }
  22. ?>
  23. <body bgcolor="#ffffff">
  24.  
  25. <form method="post">
  26. Choose a fruit:<br><br>
  27. <input type="checkbox" name="fruit[]" value="apples">apples <br>
  28. <input type="checkbox" name="fruit[]" value="oranges">oranges <br>
  29. <input type="checkbox" name="fruit[]" value="peaches">peaches <br>
  30. <input type="checkbox" name="fruit[]" value="mangos">mangos<br>
  31. <input type="submit">
  32. </form>
  33.  
  34. </body>
  35. <html>
  36.  
  37.  
Expected Output:
Suppose you check 1 and 3 checkbox. the output wil be:

You chose the following fruits:
1) apples
2 N
3) peaches
4) N

Suppose you check none of the checkboxes . the output wil be:
1) N
2) N
3) N
4) N

Related help is highly appreciated and thanks to all.

AHM
Oct 29 '07 #1
2 2371
Atli
5,058 Expert 4TB
Hi.

First of all, the $HTTP_POST_VARS array is deprecated and should not be used. Use the $_POST super-global instead.

Checkboxes will not be included in the POST data if they are not check, as I think you know. So the only way to really do what you ask is to either:
A. Send each checkbox with its own name and check which of them were sent in your PHP code, or
B. Send them all in an array and check which values you are getting in your PHP code.
Oct 29 '07 #2
ahmurad
19
Thanks for your proper guide.

is there any help so that when any checkbox is remaining to select then will crete a warning message specifying the related checkbox number.
Oct 29 '07 #3

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

Similar topics

2
by: Bryce Maschino | last post by:
hello, i'm working on a project searching through a list of arrays based on user input. the problem is that if a user does not define a certain variable, my if statement will not evaluate. i need...
2
by: FizzBin | last post by:
We are writing a C application that is using ODBC to insert records into a database. We have a NOT NULL column that can legitimately have an empty value, i.e. we know the value and it is empty...
2
by: Chris Herring | last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag and drop weenie, not a real programmer. So I tend to get confused when things do not look like the instructions said they...
11
by: Jerome | last post by:
Hi, I've got the following problem: I'm retrieving data from an SQL Server database (the data itslef was entered by an ASP form). And on an 'edit form' I want to display a checked box in the...
5
by: darrel | last post by:
I have the following right now to enter a date into SQL getting the data from some pull down menus: ------------------------------------------------- dim dateCCJApprovedDate as DateTime if...
0
by: =?Utf-8?B?SGVtYW50?= | last post by:
Hi All Please help me. I have a Datagrid with Checkbox in template field. Chexkbox datatype is bit in sql server. after binding the data, How i will sabve again the data into database if i have...
9
by: =?Utf-8?B?UGV0ZXJX?= | last post by:
I have a TabControl on a Windows form in which I have various tab pages each with a DataGridView, the first column of which is a DataGridViewCheckBoxColumn and subsequent columns being...
14
by: Richard Heathfield | last post by:
In an otherwise excellent article, Eric Sosman said: <snip> ....or will read it without ever writing it, in which case the initialisation value protects you against reading an indeterminate...
5
by: hollyquinn | last post by:
Hi I am working with a web application where I am selecting values from a SQL Server 2005 database and then loading the values into different controls on my page. Most of the values load with no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.