[solved] Check box values returns null

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
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

[solved] Check box values returns null

Post by Addos »

I wonder if anybody can tell me why this works

Code: Select all

$message .= 'Last  Name: ' .$_POST['last_name']. "\r\n";
and this doesn’t?

Code: Select all

$message .= 'Championship: You said - ' .$_POST['champ_no']. "\r\n";
Basically I’m trying to return the values of a form to send out in an email but for some reason the second one above is returning a ‘null' value.

This second one uses a check box:

Code: Select all

<input type=&quote;checkbox&quote; name=&quote;champ_no&quote; value=&quote;&quote; >
and the insert into the database for this is:

Code: Select all

GetSQLValueString(isset($_POST['champ_no']) ? "true" : "", "defined","'Yes'","'No'"),
So can anyone tell or show me why I cannot get the ‘yes’ ‘no’ value of the check box to be returned.
Thanks a mil
Brian
Last edited by Addos on Tue Jun 28, 2005 3:05 pm, edited 1 time in total.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

add something to the value attribute.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Checkboxes do not return a value. They return 'on' if they are checked, and are not even posted if they are not. A little weird to be honest. So, if you want to check the value of a checkbox, just check if it exists in $_POST:

Code: Select all

if(isset($_POST['champ_no']))
{
  $output_value = "blah blah";
}
else
{
  $output_value = "some other blah";
}

$message .= 'Championship: You said - ' .$output_value. "\r\n";
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

yes they do return values:

try this:

Code: Select all

<?
if(isset($_POST['mycheck']))
	echo $_POST['mycheck'];
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<form method="post" name="MyForm">
<input type="checkbox" name="mycheck" value="bob" onClick="document.MyForm.submit()">
</form>


</body>
</html>
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Post by Addos »

Thanks veery much to both of you I have this sorted now. In the end I used 'pickle's' methid and works a treat now.
Just wish I'd thought of it meself!
Thanks again
Brian
:wink:
Post Reply