What I'm trying to acomplish is to have a list of years in a <form> with a checkbox for each year and let the user select what year applies to the post such as: 2008, 2009, 2012 (they might select 4 out of 5 years, not just one year). Then after the user submits this form I need it to post the variable say as: $2009=2009, $2008=2008 so I can use those variables to select a unique id out of the mysql db.
Not sure if I'm on a wild goose chase with my code, but so far I got:
post.php looks like:
<form method="POST" action="post1.php?id=<?=$id?>&cat=<?=$cat?>">
<p>
<span id="title">Select years that apply to vehicle:</span><br />
<input type="checkbox" name="formDoor[]" value="2012" />2012<br />
<input type="checkbox" name="formDoor[]" value="2011" />2011<br />
<input type="checkbox" name="formDoor[]" value="2010" />2010<br />
<input type="checkbox" name="formDoor[]" value="2009" />2009<br />
<input type="checkbox" name="formDoor[]" value="2008" />2008 />
<input type="submit" value="Submit" />
</form>
The for my post1.php it looks like:
<?php
include 'connect.php';
$aDoor = $_POST['formDoor'];
if(empty($aDoor))
{
echo("You didn't select any years.");
}
else
{
$N = count($aDoor);
echo("You selected $N years(s): ");
for($i=0; $i < $N; $i++)
{
echo ($aDoor[$i] . " ");
}
}
?>
I dont have my insert statment done yet since I cant figure out how to create these variables. I guess I'm not sure if there should be a foreach loop or stick with this one? Right now it comes out to echo "You selected 4 years: 2008 2009 2010, but they dont have variable attach to each one..If anyone can help me I sure would appreciate it. :) I know its not the most advanced code, and might not even be the correct way to go about doing it, but thats why I need an expert to look at it. Thanks!