lofaifa Posted December 1, 2011 Share Posted December 1, 2011 soo i get info from a form and i want to search for it in my db .. if i find user_name AND user_password the $result returns true .. otherwise false .. <?php require_once("../includes/connection.php"); ?> <?php $user_name=$_POST["user_name"]; $user_password=$_POST["user_password"]; ?> <?php $query = "SELECT * FROM users WHERE '{$user_name}' = user_name AND '{$user_password}'= user_password "; $result = mysql_query($query,$connection); if($result==false){ redirect("../index.php");} elseif($result==true){ redirect("../welcome.php"); } ?> <?php //close connection! mysql_close($connection); ?> but the problem is that it always returns TRUE !!!! whats the problem here exactly ??? Quote Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/ Share on other sites More sharing options...
Spring Posted December 1, 2011 Share Posted December 1, 2011 mysql_result mysql_fetch_array if($row = mysql_fetch_array($result)){ redirect("../welcome.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/#findComment-1292861 Share on other sites More sharing options...
Pikachu2000 Posted December 1, 2011 Share Posted December 1, 2011 If mysql_query() returns FALSE, it means the query failed. An empty results set is not the same as a failed query. Quote Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/#findComment-1292862 Share on other sites More sharing options...
denno020 Posted December 1, 2011 Share Posted December 1, 2011 if(mysql_num_rows($result) == 0)){ redirect("../index.php");} elseif(mysql_num_rows($result) == 1){ redirect("../welcome.php"); } That will count the number of entries that is returned from your query string. This should either be a 1 or 0, unless you have an error in your database somewhere.. Quote Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/#findComment-1292864 Share on other sites More sharing options...
lofaifa Posted December 1, 2011 Author Share Posted December 1, 2011 problem solved .. thank you guys ! Quote Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/#findComment-1292868 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.