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 ??? Link to comment https://forums.phpfreaks.com/topic/252170-mysql-query-result-returns-always-true/ Share on other sites More sharing options...
Guest Posted December 1, 2011 Share Posted December 1, 2011 mysql_result mysql_fetch_array if($row = mysql_fetch_array($result)){ redirect("../welcome.php"); } 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. 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.. 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 ! 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
Archived
This topic is now archived and is closed to further replies.