-1

I'm having an issue when I enable the code below that it is causing my code to crash. I can't figure out where its crashing but I know if I comment out this portion that it will allow the code to run, just not have the checks ran on the other portions of the form.

if (empty($_POST["SCreq"])) {{
    $SCreqERR = "SC requires a Yes or No answer";
} else {
    $SCreq = test_input($_POST["SCreq"]);}
    //  elseif($SCreq = "Yes"; $Email=False)
    //  $EmailERR = "Email is required for SC"
    //  elseif ($SCreq = "Yes"; $emaildist1 = "")
    //  $emaildist1ERR = "First Email Distrobution Group required with SC"
    //  else {
   //       $emaildist1 = test_input($_POST["emaildist1"])
}}

Any help would be greatly appreciated, I have everything name, and all is the correct case.

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54
  • Check the error logs to see what makes it crash. What are you attempting to do in your elseif? `elseif($SCreq = "Yes"; $Email=False)` doesn't really make sense – JimL Jun 03 '16 at 17:26
  • Why do you have `{{` and `}}`. One set of braces should be enough :-P – gen_Eric Jun 03 '16 at 17:28
  • I guess test_input() is unknown in your page – Mojtaba Jun 03 '16 at 17:29
  • 2
    Helpful for the future (or now) : [How do I get PHP Errors to display?](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – HPierce Jun 03 '16 at 17:31
  • Also useful: php -l /path/to/your/script. You have too many syntax errors (incorrect if conditions, messy nesting, incorrect variable comparisons (= instead of ==), ...) – NaeiKinDus Jun 03 '16 at 17:48

3 Answers3

1

The double-quotes basically start a new block within your "if" block. So, your code could be written like this:

if (empty($_POST["SCreq"])) {
    {
        $SCreqERR = "SC requires a Yes or No answer";
    }
    else {
        $SCreq = test_input($_POST["SCreq"]);
    }
}}

Not only are the brackets unbalanced (there's more closing brackets than opening brackets), the "else" also starts inside the "if" block. Removing the {} inside the "if", you get

if (empty($_POST["SCreq"])) {
    else {
        $SCreq = test_input($_POST["SCreq"]);
    }
}}

which isn't valid (the "else" has to come directly after the "if" block, not within it).

Use proper indenting to catch those mistakes quickly. After each "{", start a new line, and indent your code more. After each "}", start a new line, and indent less. After each block, you need to be at the same indent-level as you were before, otherwise you have extra "{"s or "}". You can either do that manually, or have a good editor that does it for you. This kind of code uses proper indenting, and would be valid:

if (empty($_POST["SCreq"])) {
    $SCreqERR = "SC requires a Yes or No answer";
}
else {
    $SCreq = test_input($_POST["SCreq"]);
}
Aaa
  • 614
  • 5
  • 14
0

Use an IDE to help check that things are nested correctly. Hard to tell with things commented out though but... {{. Also, error logs!

I assume you looked at the documentation? http://php.net/manual/en/control-structures.elseif.php

if ($a > $b) {
  echo "a is bigger than b";
} elseif ($a == $b) {
  echo "a is equal to b";
} else {
  echo "a is smaller than b";
}
ficuscr
  • 6,975
  • 2
  • 32
  • 52
-2
elseif($SCreq == "Yes" && $Email == False)
  $EmailERR = "Email is required for SC";
  elseif ($SCreq == "Yes" && $emaildist1 == "")
  $emaildist1ERR = "First Email Distrobution Group required with SC";
  else {
      $emaildist1 = test_input($_POST["emaildist1"]);}

Condition test is ==

multiple AND condition put &&.

End your statements with ;

Moussa Khalil
  • 635
  • 5
  • 12