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:
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.
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!
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!