synking Posted March 4, 2009 Share Posted March 4, 2009 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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/ Share on other sites More sharing options...
47.46.45 Posted March 4, 2009 Share Posted March 4, 2009 I'm assuming that in your actual document you closed your else and PHP tags 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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776409 Share on other sites More sharing options...
synking Posted March 4, 2009 Author Share Posted March 4, 2009 yeah the if statement is in the middle of a frame page and it was not working i will try what you suggested and see if that helps. Link to comment https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776415 Share on other sites More sharing options...
synking Posted March 4, 2009 Author Share Posted March 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776422 Share on other sites More sharing options...
47.46.45 Posted March 4, 2009 Share Posted March 4, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776427 Share on other sites More sharing options...
synking Posted March 4, 2009 Author Share Posted March 4, 2009 $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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776439 Share on other sites More sharing options...
47.46.45 Posted March 4, 2009 Share Posted March 4, 2009 $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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776446 Share on other sites More sharing options...
kickstart Posted March 4, 2009 Share Posted March 4, 2009 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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776450 Share on other sites More sharing options...
synking Posted March 4, 2009 Author Share Posted March 4, 2009 Ok cool after doing what you suggested it all works now thanks guys. Link to comment https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776451 Share on other sites More sharing options...
47.46.45 Posted March 4, 2009 Share Posted March 4, 2009 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 https://forums.phpfreaks.com/topic/147935-solved-matching-two-post-variables-in-if-statements/#findComment-776452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.