My problem is as follows. This is my mySQL table, and HTML form. I need to findout a PHP code to insert the checkbox data to mySQL table.
If a checkbox is checked I want to fill that particular column as "1" else fill it as "0".
A single row is added in one time.
I am using 2 PHP files.
1) regForm.php
<html>
<form method="get" action="regCode.php">
ID: <input type="text" name="id"/></br>
Select Available dates: </br>
Monday <input type="checkbox" value="monday"></br>
Tuesday <input type="checkbox" value="tuesday"></br>
Wednesday <input type="checkbox" value="wednesday"></br>
Thursday <input type="checkbox" value="thursday"></br>
Friday <input type="checkbox" value="friday"></br>
<input type="submit" value="Submit"/><br></br>
</html>
2) regCode.php
<html>
<body bgcolor="#FFFCC">
<?php
$dbhost='localhost';
$dbuser='username';
$dbpass='password';
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
if(!$conn)
{
die('could not connect'.mysql_error());
}
$sql="INSERT INTO available_days (monday, tuesday, wednesday, thursday, friday) VALUES
()";
mysql_select_db('testdb');
$retval=mysql_query($sql,$conn);
if(!$retval)
{
die('could not add data'.mysql_error());
}
$message="Successfully Added ID No: ".mysql_insert_id();
echo "<script type='text/javascript'>alert('$message'); window.location.href='regForm.php';</script>";
mysql_close($conn);
?>
</body>
</html>
isset(). It returns a boolean, but if cast to an integer it will give your 1 or 0.$monday = (int)isset($_POST['monday'])- now you just need to insert it ;-)