Forum Moderators: coopster
<label><input name="veggie1" value="1" type="checkbox">Thursday</label>
<label><input name="veggie2" value="1" type="checkbox">Friday</label> On the 2nd page
$veggie1=$_POST['veggie1'];
$veggie2=$_POST['veggie2'];
mysql_query("INSERT INTO data (name, address, city, state, zip, phone,emails ,hospice_affiliation, discipline_code, is_member, pre_conf_day1, pre_conf_day2, pre_conf_day3, leadership_earlybird, leadership_registered,veggie1)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$phone', '$emails', '$hospice', '$discipline', '$member', $confday1, $confday2, $confday3, $earlybird, $registered, $veggie1 )"); Just to let everyone know that these 3 variable ( $confday1, $confday2, $confday3) are also checkboxes that only work if selected also.
The entire script stops if all checkboxes are not selected and nothing is stored in the database.
They are being stored in a mysql database as a tinyint default 0.
What can I do to resolve this?
[edited by: jatar_k at 3:51 pm (utc) on June 6, 2007]
[edit reason] fixed sidescroll [/edit]
$veggie1 = (isset($_POST['veggie1']) && $_POST['veggie1'] == '1')? 1 : 0;
$veggie2 = (isset($_POST['veggie2']) && $_POST['veggie2'] == '1')? 1 : 0;
Also, you should make sure you are escaping user input with mysql_real_escape_string() [php.net] to prevent sql injection attacks.
$radio1 = (isset($_POST['radio1']))? $_POST['radio1'] : 'default';
You can also do that for checkboxes, actually. The extra check and forcing it to a 1 or 0 just skips the need to validate what is provided in the checkbox post array. Using the code above, you'll still need to use mysql_real_escape_string on the $radio1 value.
<label>
<input name="pre_conf_day1_track" value="A1" type="radio">
A1 </label> <label>
<input name="pre_conf_day1_track" value="A2" type="radio">
A2 </label> <label>
<input name="pre_conf_day1_track" value="A3" type="radio">
A3 </label> <label>
<input name="pre_conf_day1_track" value="A4" type="radio">
A4 </label> <label>
<input name="pre_conf_day1_track" value="A5" type="radio">
A5 </label> <label>
<input name="pre_conf_day1_track" value="A6" type="radio">
A6 </label> <label>
<input name="pre_conf_day1_track" value="A7" type="radio">
A7 </label> <label>
<input name="pre_conf_day1_track" value="A8" type="radio">
A8 </label> <label>
<input name="pre_conf_day1_track" value="A9" type="radio">
A9 </label> The process.php is as follows:
$conftrack1 = (isset($_POST['pre_conf_day1_track']))? $_POST['pre_conf_day1_track'] : 'default';
mysql_query("INSERT INTO data (name, address, city, state, zip, phone, emails, hospice_affiliation, discipline_code, is_member, pre_conf_day1, conftrack1, pre_conf_day2, pre_conf_day3, leadership_earlybird, leadership_registered, veggie1, veggie2)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$phone', '$emails', '$hospice', '$discipline', '$member', $confday1, $conftrack1, $confday2, $confday3, $earlybird, $registered, $veggie1, $veggie2 )"); The MYSQL database is TEXT NULL
[edited by: jatar_k at 9:14 pm (utc) on June 6, 2007]
[edit reason] fixed sidescroll [/edit]
TO
mysql_query("INSERT INTO data (name, address, city, state, zip, phone, emails, hospice_affiliation, discipline_code, is_member, pre_conf_day1, conftrack1, pre_conf_day2, pre_conf_day3, leadership_earlybird, leadership_registered, veggie1, veggie2)
VALUES ('$name', '$address', '$city', '$state', '$zip', '$phone', '$emails', '$hospice', '$discipline', '$member', '$confday1', '$conftrack1', '$confday2', '$confday3', '$earlybird', '$registered', '$veggie1', '$veggie2')")or die(mysql_error());
I have put the single quotes for you. See what kind of error it generates. If it just exits, it seems there was an error somewhere but couldn't display it.
Habtom