I am having a problem inserting the value from a checkbox into a MySQL table. The checkbox is used as a yes or no answer. When the box is checked it works fine, when it is not checked I get...
Notice: Undefined variable: dnr in c:\inetpub\wwwroot\dev\php\addvisit.php on line 15
If I could either fix the problem so the error message doesn't fix, or suppress the error message so it doesn't print on the screen.
If dnr is checked it echos 1
if dnr is not checked I get the error and echos 0
Here is the relevent part of my code:
<?php
if(isset($Submit)){
$db = mysql_connect('localhost', 'user','');
mysql_select_db('census',$db);
if ($dnr == "") {
($dnr = "0");
}
else{
($dnr ="1");
}
echo $dnr;
$query=mysql_query("INSERT INTO table SET DNR='$dnr'");
}
else
{
?>
<div align="center">
<form method="post" action="<?php echo $PHP_SELF?>">
....
<input type="checkbox" name="dnr">
....
<input type="submit" name="Submit" value="Submit">
</form>