Jump to content

Help - Checkboxes keep showing up as "No" in MySQL Database


Go to solution Solved by AbraCadaver,

Recommended Posts

Fairly new to PHP, so I am apologizing up front:

 

Trying to get a couple check boxes to work when going to a MySQL database. They keep coming up "No" no matter what I do:

 

Form Page:

 

 

<?php
if($_COOKIE['newsletter']=='No') echo ' <input type="checkbox" name="newsletterselect[]" value="newsletter" /><label class="Text"> Newsletters by Email   </label>';
else echo '<input type="checkbox" name="newsletterselect[]" value="newsletter" checked /><label class="Text"> Newsletters by Email</label><br>';
?>
 
Processing Code:
 
$newslettersselect[0]='No';
if(isset($_POST['newslettersselect'])){
foreach ($_POST['newslettersselect'] as $value){
if($value=='newsletters') $newslettersselect[0]='Yes';
}
}
setcookie("newsletters", $newslettersselect[0], null, "/", ".WEBSITENAMEHERE.com");

 

I have noticed that whenever I change the first line of the processing code (currently where it says 'No', that is the answer that shows up. If I change that to "yes", then I get "yes" in the database every time.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.