Hello out there!!!
I would be grateful if you could give a hand here! I want to pass a value to a boolean column in the database (MySQL) with a checkbox. After submit button is pressed I have to show that the checkbox is still enabled, if there is such a value (boolean) in the database has already been passed or existed.
In my include file .inc there is a function:
function display_check(){
$php_self = $_SERVER['PHP_SELF'];
$reg_str = <<< EOREGSTR
<h2><strong>Referees' letters have been received</strong>
<input type="checkbox" name="checkbox1" value="1" $checked></h2><br></form>
EOREGSTR;
echo $reg_str;
}
?>
which I call in my regular php file::evilgrin:
if ($POST['submit'] == 'Submit') {
global $checkbox;
$checkbox = $GET['checkbox1'];
$query = "select * from comments where AID = $aid and SID = $sid and part = $part";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
if ($rows < 1){
if(empty($checkbox)){
$check='NULL';
$checked = "";
}else {
switch ($checkbox)
{
case "1":
$check = 1;
$checked = "checked";
break;
default:
$check = 'NULL';
$checked = "";
break;
}
}
$query = "insert into comments values
($aid,$sid,$part,'$comments',NULL,'$check',NOW(),NULL)";
$result = mysql_query($query) or die ("error inserting comments");
//echo '<h3> Comments submitted </h3>';
}else{
if (empty ($checkbox)){
$check='NULL';
$checked = "";
}else {
switch ($checkbox)
{
case "1":
$check = 1;
$checked = "checked";
break;
default:
$check = 'NULL';
$checked = "";
break;
}
Obviously something is wrong and I can not find it. Could you please share your thoughts?
Thanx a lot in advance!