So I wasnt sure which section to post this in as it deals with PHP and MySQL, However.. here's my issue. I have a registration form that was pre generated through a form generator. I wanted to add a check box to people can choose weather or not they want to subscribe to the newsletter. I added the checkbox to the form, and modified the code so it would insert a value into the SQL database. The problem is, weather it's checked or not it simply puts the value of '0' into the column. My goal here is to have a 0 if unchecked, and a 1 if checked. Any suggestions?
It's because a checkbox is "on" on the callback from _POST/_GET. You'll have to do something along the lines of: $myCheckValue = $_POST["myCheckBox"]; if ($myCheckValue == "on") { $myCheckFieldValue = 1; } else { $myCheckFieldValue = 0; } Then in your SQL you will be writing the $myCheckFieldValue variable assuming the field is of bool (tinyint) type.
You set the value of the checkbox when you make it, add value="0" for the no option and value="1" for the yes option. Then insert that into your database like, PHP $checkbox = $_POST['checkbox']; PHP: MySQL INSERT INTO table (checkbox) VALUES ('$checkbox') Code (markup):