Search code examples
phpformspostcheckboxhandle

PHP form check box issue


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";
}  

Solution

  • 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";
    }