Simple way to add something to a database table using HTML check boxes

Hey guys, I am trying to figure out a way to add a day of the week to my day column, allowing the user to select from 7 boxes, one for each day of the week. Once selected the user enters a time and submits this, this is then added to the table as a booking. I thought it would be easier to do this than it apparently is. So far I only have my check boxes in HTML:

<div id="daySelection">
				
				<form method="post" action="fam_req.php">
				<input type="checkbox" name="monday" value="1" /> Monday<br />
				<input type="checkbox" name="tuesday" value="female" /> Tuesday<br />
				<input type="checkbox" name="wednesday" value="tuesday" /> Wednesday<br />
				<input type="checkbox" name="thursday" value="wednesday" /> Thursday<br />
				<input type="checkbox" name="friday" value="friday" /> Friday<br />
				<input type="checkbox" name="saturday" value="saturday" /> Saturday<br />
				<input type="checkbox" name="sunday" value="sunday" /> Sunday
				
				
				</div>

Is there a way that I can ensure that only one check box is selected, and depending on the check box, selected, set thatl to a value which I can use as a variable and pass it to the table in my INSERT query?

If someone can show me hoe to use a check box to get a value I can use in PHP I am sure I can do the rest.

I appreciate any help whatsoever!

Many thanks.


<input type="checkbox" name="monday" value="[COLOR="#FF0000"]1[/COLOR]" /> Monday<br />
<input type="checkbox" name="tuesday" value="[COLOR="#FF0000"][/COLOR][COLOR="#FF0000"]female[/COLOR]" /> Tuesday<br />
<input type="checkbox" name="wednesday" value="[COLOR="#FF0000"][/COLOR][COLOR="#FF0000"]tuesday[/COLOR]" /> Wednesday<br />
<input type="checkbox" name="thursday" value="[COLOR="#FF0000"][/COLOR][COLOR="#FF0000"]wednesday[/COLOR]" /> Thursday<br />
<input type="checkbox" name="friday" value="friday" /> Friday<br />
<input type="checkbox" name="saturday" value="saturday" /> Saturday<br />
<input type="checkbox" name="sunday" value="sunday" /> Sunday

sorry, can’t help you with the php, but i thought i’d mention that you should really fix those values or else you’re going to be storing garbage

Oops!! I’m sorry, I should have checked that code first! I started this a while back couldn’t do it then, I’ll fix this when I get home!
Thanks for the heads up, I would have caught this but maybe not until I was getting some confusing errors!

:wink:

Cheers !!


<input type="checkbox" name="[B]dayofweek[][/B]" value="monday" /> Monday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="tuesday" /> Tuesday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="wednesday" /> Wednesday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="thursday" /> Thursday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="friday" /> Friday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="saturday" /> Saturday<br />
<input type="checkbox" name="[B]dayofweek[][/B]" value="sunday" /> Sunday

Give all check-boxes the same name, followed by .
That way the php script you’re sending the form to will receive the check-box data in an array.


print_r($_POST['dayofweek']);

You can use javascript to check client side that only one check-box is checked, but you will still have to check that server side as well (hint: the array should contain one element).

Hey guys I decided to use radio buttons because that was easier when requiring exclusivity! It was actually easy, just like posting data in a form, except it was the value of the radio button being passed!

Many thanks!!!