I have this form, but now need to know how to move each box into a database table but don't know how.
<form action="availability.php" method="post">
<input type="checkbox" name="mon9-11" value="mon9-11" />
<input type="checkbox" name="mon11-1" value="mon11-1" />
<input type="checkbox" name="mon1-3" value="mon1-3" />
<input type="checkbox" name="mon3-5" value="mon3-5" />
<input type="checkbox" name="mon5-7" value="mon5-7" />
<input type="checkbox" name="mon7-9" value="mon7-9" />
<input type="submit" name="submit" value="Done" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
Please can someone make the script to move the info to a database table?
How do I add the checkboxes to a database table?
Moderator: General Moderators
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: How do I add the checkboxes to a database table?
if chcekboxes are checked by user only then the relevant $_POST / $_GET variable is set, otherwise they are not submitted with the form.
So in availability.php you can check which checkbox is checked by using something like ..
Then depending on $mon911chk value you can set your database field. You can automate the process if you use some logic in defining the cehckbox names. Otherwise you will have to write the code for each checkbox.
So in availability.php you can check which checkbox is checked by using something like ..
Code: Select all
if(isset($_POST['mon9-11']))
$mon911chk=1
else
$mon911chk==0-
klevis miho
- Forum Contributor
- Posts: 413
- Joined: Wed Oct 29, 2008 2:59 pm
- Location: Albania
- Contact:
Re: How do I add the checkboxes to a database table?
Or you can do:
if(isset($_POST['mon9-11'])) {
//insert this in the database table
if(isset($_POST['mon9-11'])) {
//insert this in the database table
-
dimxasnewfrozen
- Forum Commoner
- Posts: 84
- Joined: Fri Oct 30, 2009 1:21 pm
- phdatabase
- Forum Commoner
- Posts: 83
- Joined: Fri May 28, 2010 10:02 am
- Location: Fort Myers, FL
Re: How do I add the checkboxes to a database table?
Or you could save yourself a lot of typing:
...
<input type='checkbox' name='available[]' value='mon11-1' />
...
to save it:
if( array_key_exists( 'available', $_POST)) {
foreach( $available as $item=>$value) {
${$item) = $value;
}
}
Which will give you a 'list' of values:
...
$mon11-1 = 'mon11-1'
...
...
<input type='checkbox' name='available[]' value='mon11-1' />
...
to save it:
if( array_key_exists( 'available', $_POST)) {
foreach( $available as $item=>$value) {
${$item) = $value;
}
}
Which will give you a 'list' of values:
...
$mon11-1 = 'mon11-1'
...