hi
How do I write php code to check if checkbox is checked or not ?
correct my red line please :)
<html>
<head>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function add()
{
<?php
extract($_POST);
if(category[0].checked)
$query = "INSERT INTO mytable (cat) VALUES ('1')
if(category[1].checked)
$query = "INSERT INTO mytable (cat) VALUES ('2')
if(category[2].checked)
$query = "INSERT INTO mytable (cat) VALUES ('3')
if(category[3].checked)
$query = "INSERT INTO mytable (cat) VALUES ('4')
if(category[4].checked)
$query = "INSERT INTO mytable (cat) VALUES ('5')
if(category[5].checked)
$query = "INSERT INTO mytable (cat) VALUES ('6')
// connect to DB
mysql_connect ('localhost', 'root');
// select the DB
mysql_select_db('mydatabase');
// execute the query
mysql_query($query);
?>
return true;
}
</script>
<form name="myform" method ='post' onsubmit="add();">
<input name="category" type="checkbox" value="flowers"/>
<input name="category" type="checkbox" value="animals"/>
<input name="category" type="checkbox" value="children"/>
<input name="category" type="checkbox" value="nature"/>
<input name="category" type="checkbox" value="nature"/>
<input name="category" type="checkbox" value="other"/>
</form>
</body>
</html>
i hope i get help :(:(:(