Problem with IF statement (PHP)

Associate
Joined
2 Aug 2005
Posts
680
I'm making an application form where one of the questions is "approve application?" and there is a radio box where one sets the answer to "yes" and the other "no". For some reason I can't apply the logic to the confirmation email.
Here's the code for the question in the form:

Code:
<li class="appform">Approve application  in accordence with the above details? <br />
      Yes
      <input name="agree" type="radio" value="yes" /> 
      No 
      <input name="agree" type="radio" value="no" />
    </li>

And here's part of the php code:
Code:
if ($agree = yes) { $approve = "approved" && $messageend = 'Please note your diary but await final confirmation.';}
elseif ($agree = no) { $approve = "rejected" && $messageend = 'Please contact your manager for details.';};
It's probably something stupid :p I've also tried it with $_post['agree'].
The code to change the text in the email reads:
Code:
$subjectapp = "Application " . $approve;
and it comes up with "Application 1", how can I stop it doing this?

Thanks a lot!
Dan
 
==, not =

= is the assignment operator

== is the comparison operator.

Code:
if ($agree == 'yes') // compares the value of $agree to 'yes'

if ($agre = 'yes') // assigns 'yes' to $agree and will always equate to TRUE because it is successful.
 
I see :D Thanks mate. I think I remember that, but I just need to remember that = in PHP isn't the same as in the real world :) It's still coming up with "Application 1" for some reason. The other text $messageend is working however. I've also tried
Code:
$subjectapp = "Application $approve";
 
Just sorted it, the two statements in the IF statement shouldn't be seperated by && so I change it to ; and it's working fine. Thanks for your help Dj :D
 
Why are you using elseif? What happens if there's an erroenous value?

Use if to test the TRUE condition and then else to handle everything else (assuming you want everything apart from an explicit 'yes' to be handled with that action).
 
It may be a scenario of:

Code:
<?php

if ($agree == 'yes') {
  //yes
} elseif ($agree == 'no') {
  //no
} else {
  echo 'You must make a choice!';
}

?>

btw, use explicits variables, don't depend upon register_globals.. it's 90% confirmed it will be removed from future version of php and most hosts have it switched off regardless of verison.
 
Thanks guys, I'll change it to else, sounds like the safest option. I could use the elseif then else as you mentioned above, but it's a radiobox so there are only two possible answers. Thanks again :)
Dan
 
Back
Top Bottom