Page 1 of 1

[solved] Check box values returns null

Posted: Tue Jun 28, 2005 2:42 pm
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

Posted: Tue Jun 28, 2005 2:51 pm
by Burrito
add something to the value attribute.

Posted: Tue Jun 28, 2005 2:53 pm
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";

Posted: Tue Jun 28, 2005 2:57 pm
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>

Posted: Tue Jun 28, 2005 3:05 pm
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: