Jump to content

[SOLVED] matching two post variables in IF statements


synking

Recommended Posts

Hey i am need help on trying to match to variables together. here is what i have.

<?PHP

$win = $_POST['walkos']
$walktype = $_POST['walktype']
$email = $_POST['email']
if ($win == "XP" or "Vista" || $walktype == "email") {
              echo ("<FRAME src=\"$win\\$walktype\$email">);
} else { 
              echo ("not able to find file"); 

 

it get it's information from two drop down menus and a radio button. but it does not seem to do anything i have checked that the post data is coming over with print_r($_POST) and everyting seems to check out. but the if statement does not print anything.

 

I'm assuming that in your actual document you closed your else and PHP tags :P

 

As far as I know the proper syntax for if statements in PHP is more like

 

if ((condition1) || (condition2) || condition3)) {

echo "condition met";

}

 

So I'd have mine like this:

 

if (($win == "XP")||($win == "Vista")||($walktype == "email")) {

 

You could probably debug it a little easier if you got rid of the frame stuff in the echo commands and just had an echo "conditions met"; or something similar. At the moment you aren't closing that frame tag properly, take a look at your HTML when it loads in the browser.

i just did how you suggested but now it will only evaluates to true. and always shows condition met even if i change the form data to something i know does not evaluate true.

 

Could you paste your if statement up? Are you using double equals or singles in your conditions?

 

If you are using the exact code I put in my last post, that will only ever eval to true if one of those conditions is met. Unless I'm missing something in my 3am stupor :P

$win      = $_POST['walkos'];
$walktype = $_POST['walktype'];
$walkemail = $_POST['walkemail'];

if (($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME") || ($walktype == "email")) {
        echo "condition met \n");
} else {
        echo ("no");
}
?>

 

that is the full if statement. and what i need may be the issue i need it to match any of the values for $win and match $walktype as well. I mean that i need them both to be met to print true and if $win matches but $walktype does not it should eval to false. maybe i am doing it wrong.

$win      = $_POST['walkos'];
$walktype = $_POST['walktype'];
$walkemail = $_POST['walkemail'];

if (($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME") || ($walktype == "email")) {
        echo "condition met \n");
} else {
        echo ("no");
}
?>

 

that is the full if statement. and what i need may be the issue i need it to match any of the values for $win and match $walktype as well. I mean that i need them both to be met to print true and if $win matches but $walktype does not it should eval to false. maybe i am doing it wrong.

 

Ah I see. You don't want an OR (||) then, you want an AND (&&).

 

if (($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME") && ($walktype == "email")) {

 

Give that a try.

Ah I see. You don't want an OR (||) then, you want an AND (&&).

 

if (($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME") && ($walktype == "email")) {

 

Give that a try.

 

Hi

 

To make the operator precedence a bit more obvious I would suggest adding a couple of extra brackets

 

if ((($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME")) && ($walktype == "email")) {

 

 

All the best

 

Keith

Ah I see. You don't want an OR (||) then, you want an AND (&&).

 

if (($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME") && ($walktype == "email")) {

 

Give that a try.

 

Hi

 

To make the operator precedence a bit more obvious I would suggest adding a couple of extra brackets

 

if ((($win == "XP") || ($win ==  "Vista") || ($win ==  "2000") || ($win ==  "98") || ($win ==  "ME")) && ($walktype == "email")) {

 

 

All the best

 

Keith

 

You should definitely do this, the one I posted will work for now but is going to give you headaches in the long run.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.