Jump to content

mysql query result returns always true!


lofaifa

Recommended Posts

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

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.