play_ Posted February 10, 2008 Share Posted February 10, 2008 I haev an SQL class. Here's what the query method looks like: function query($query) { $this->result = @ mysql_query($query, $this->linkid); if(!$this->result) { echo "--[ query failed ]--"; exit(); } } Now, I am doing something like this on another page: $sql = new SQL(); $query = "query here"; if( $sql->query($query) ) { header("Location: " . $_SERVER['PHP_SELF'] . "?result=success"); } else { echo 'problem'; } The problem with the above is that the query is indeed being ran (i checked in the database), but the page is not redirecting But the following works (it redirects): $query = 'some query here'; $sql->query($query); header("Location: " . $_SERVER['PHP_SELF'] . "?result=success"); In other words, if i take out the if statement, it works as intended. why? Quote Link to comment https://forums.phpfreaks.com/topic/90306-doing-something-like-if-sql-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2008 Share Posted February 10, 2008 Your query function does not return anything (which probably results in a null value), so an if() test will be false. Change your function to return a true value if the query did not fail. Quote Link to comment https://forums.phpfreaks.com/topic/90306-doing-something-like-if-sql-query/#findComment-463047 Share on other sites More sharing options...
roopurt18 Posted February 10, 2008 Share Posted February 10, 2008 You should also usually call exit() after redirecting. Quote Link to comment https://forums.phpfreaks.com/topic/90306-doing-something-like-if-sql-query/#findComment-463048 Share on other sites More sharing options...
play_ Posted February 12, 2008 Author Share Posted February 12, 2008 thanks guys. ps:: here is the topic solved button? Quote Link to comment https://forums.phpfreaks.com/topic/90306-doing-something-like-if-sql-query/#findComment-465067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.