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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.