Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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