0

HTML:

<form method="post" action="proc.php">
    <select name="yDept" class=sOptions>
          <option disabled value="#" SELECTED>========</option>
          <option value="acct">acct</option>
          <option value="its">its</option>
    </select>
</form>

PHP:

    $ydept = trim(strip_tags(stripslashes($_POST['yDept'])));
    $pass = 87;

    if($fname <> "" && $lname <> "" && $theemail <> "" && $ydept <> "#") {
         if ($pass >= 80) {
              echo "passed"; //take to congrats.php page
         }
         else {
              echo "no pass"; //take to nopass.php page
         }
    }
    else {
         echo "something is missing"; //take to the missing.php page
    }

What I am looking to accomplish is, if the user does not change the value of select and choose something other than the disabled value, it should take the user to missing.php page. That works if the other values are blank but when it comes to $ydept, it always kicks in nopass.php page.

Am I checking the value of the select correctly in PHP? I think that's where the issue is?

I tried the following to see if it makes a difference:

$ydept = $_POST['yDept'];

But it didn't.

Si8
  • 9,141
  • 22
  • 109
  • 221
  • Is your select codeblock inside of a
    whose method is "post"? If so, can you edit and include the whole HTML code block, form included? Also, what are $fname, $lname and $theemail? Those are other points that could make the if statement fail.
    – Eric Wich Jun 12 '13 at 15:54
  • 1
    You can't disable a single option in a ` – DaveRandom Jun 12 '13 at 15:55
  • I disabled the first option so the user cannot select it @DaveRandom But is that the reason the code isn't working? – Si8 Jun 12 '13 at 15:56
  • Where does $pass come from ? – Alexandre Danault Jun 12 '13 at 15:57
  • added the $pass just for the purpose of troubleshooting. – Si8 Jun 12 '13 at 15:59
  • 1
    Do an echo on $ydept after you set it to $_POST['yDept'] and see what's stored in there. It might help you isolate your problem. – Eric Wich Jun 12 '13 at 16:00
  • @EricWich Great point but if i leave out fname or lname or theemail, the missing.php page kicks in. So the issue is actually with yDEPT. But I shall isolate it and see what happens. – Si8 Jun 12 '13 at 16:01

1 Answers1

4

Disabled options are not submitted with the form, so you are currently checking:

("" <> "#") //TRUE

You can either remove the "disabled" on the <option> or change your IF statement:

if($fname <> "" && $lname <> "" && $theemail <> "" && (!empty($ydept) && $ydept <> "#"))
Jacob S
  • 1,693
  • 1
  • 11
  • 12
  • hey jacob please undelete your answer at http://stackoverflow.com/questions/17365358/multidimensional-array-conversion-is-not-working because that is the perfect solution for my problem.... – Dipesh Parmar Jul 02 '13 at 09:45