0

I have a simple form that I'm trying to add a checkbox to, I have everything on the form setup correctly but when I try to handle the check box I'm only able to make echos work. I'm trying set whether the box is checked as a yes or no and store that yes/no in a variable, here is what I have in my handle form for the checkbox:

    if(isset($_POST['race']) && 
   $_POST['race'] == 'Yes') 
{
    $race1 == "yes";
}
else
{
    $race1 == "No";
}  
2
  • I'm not sure how this code snippet relates to a form. Can you provide your form html? Commented Aug 29, 2014 at 17:16
  • if you are trying to default a checkbox to checked add the attribute checked="checked" Commented Aug 29, 2014 at 17:17

2 Answers 2

2

You need to use the single equal sign when assigning values. Double equals does a comparison.

if(isset($_POST['race']) && $_POST['race'] == 'Yes') 
{
  $race1 = "yes";
}
else
{
  $race1 = "No";
}  
Sign up to request clarification or add additional context in comments.

Comments

0

== is a comparison operator. You need to use attribution operator =

if (isset($_POST['race']) &&
    strtolower($_POST['race']) == 'yes') 
{
    $race1 = 'yes';
}
else
{
    $race1 = 'No';
}  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.