spiceydog Posted July 17, 2008 Share Posted July 17, 2008 I don't know if it's possible to use OR in an If statement but regardless that's basically what I've been trying to do. I need there to be two possible reasons why an if statement should activate. Here is what I have: if (($fromcheck == $username) || ($tocheck == $username)) { } But the problem with that is it just posts the data twice and I'm not sure why. FYI: it's impossible for both $fromcheck and $tocheck to both equal $username at the same time. Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/ Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 That is a perfectly valid expression, post the rest of the relevent code and well try and help. Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592207 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 I guess this is the only relevant code... The rest is just what happens if the if statement is correct. $querycheck = "SELECT * FROM mail WHERE mid = '$mid'" or die(mysql_error()); $resultcheck = mysql_query($querycheck) or die("Couldn't execute query because: ".mysql_error()); while($rowcheck = mysql_fetch_array($resultcheck)){ $fromcheck = $rowcheck['fromwho']; $tocheck = $rowcheck['towho']; if (($fromcheck == $username) || ($tocheck == $username)) { Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592214 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Isn't your problem with what is happening within the if() ? And whats with this die() statement? $querycheck = "SELECT * FROM mail WHERE mid = '$mid'" or die(mysql_error()); All your doing there is assigning a string to a variable, nothing to do with mysql. Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592215 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 I don't know how it could be within the if() because what's going wrong is EVERYTHING within the if() is being posted twice. However if I change the if statement to: if ($fromcheck == $username) { It works. When I get pissed I tend to throw or dies randomly around.... lol Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592220 Share on other sites More sharing options...
trq Posted July 17, 2008 Share Posted July 17, 2008 Could your query possibly be returning two results, one in which $fromcheck == $username and another where $tocheck == $username ? Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592228 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 Ahhh!! that's it... i forgot that there were multiple lines where mid = '$mid' and that a few of them switched the fromwho and towho so now it works! yay! Thanks for all your help! Link to comment https://forums.phpfreaks.com/topic/115170-using-or-with-if-statements/#findComment-592239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.