checkboxes mysql php
Posted: Mon Jun 23, 2008 4:04 pm
Hello,
I am having a hard time getting checkboxes. What I would like to do is if it is checked, it go into the database. This is how I've set them up in my database:
tinyint 1, unsigned, null
This is how I've set it up in my html form:
What I don't understand is the php part of it. I'm a newbie when it comes to learning this stuff, so please bear with me! This is what I've gathered so far, but I'm so unsure of what it all means.
And this is what I gathered if I were on a page where I needed to pull that info back out of the database:
Any ideas or suggestions will be much appreciated!!!
Thanks,
~Amy
I am having a hard time getting checkboxes. What I would like to do is if it is checked, it go into the database. This is how I've set them up in my database:
tinyint 1, unsigned, null
This is how I've set it up in my html form:
Code: Select all
<form action="" method=POST>
<input type=checkbox name=features[] value=alarm> Alarm
<input type=checkbox name=features[] value=ac>Central AC
<input type=checkbox name=features[] value=cyard>Courtyard
</form>
Code: Select all
<?php
foreach($features as $featuresname)
{
$query = "insert into table (alarm,ac, cyard)values(????????????????????)";
$result = mysql_query($query) or die ("query not made");
?>
Code: Select all
<?php
include ("");
mysql_connect("$host", "$user", "$password") or die ("cannot connect to server");
mysql_select_db("$database") or die ("cannot select DB");
!isset($_POST['features']));
foreach ($features as $featuresname)
{
echo "$featuresname";
}
?>
Thanks,
~Amy