Jump to content

help pls...


cahcs

Recommended Posts

whats wron with dis code??? even if i input the correct username and password it still prompt me "Invalid username or password!"..???

 

 

 

 

<?

session_start();

 

include("connect.php");

 

if (isset($_POST["Login"]))

{

$username = $_POST["username"];

$password = md5($_POST["password"]);

 

$result = mysql_query("select * from user where username = '".$username."' and password = '".$password."'");

$isExist = mysql_num_rows($result);

 

if ($isExist == 1)

{

$_SESSION["username"] = $password;

echo '<script>location.href="tutorials[1].php";</script>';

 

}

else

{

echo '<script>alert("Invalid username or password!");

history.go(-1);</script>';

}

}

 

else

{

echo '<script>location.href="index.php";</script>';

}

 

 

?>

Link to comment
Share on other sites

FILTER USER INPUT!!!

 

I know this isn't what you asked, but it is VERY IMPORTANT!  Your code is open to sql injection.

 

Okay, now to answer your question.  Get rid of the password in your sql query.  Just look for rows where the username matches, then (for debugging) echo the hash of the user supplied password and the password hash retrieved from the database.

 

Link to comment
Share on other sites

  $result = mysql_query("select * from user where username = '".$username."' and password = '".$password."'") or die(mysql_error());

  $isExist = mysql_num_rows($result);

 

echo 'rows returned: '.$isExist;

 

 

 

use that to see if there are any errors in the query as well as seeing what value $isExist has.

 

 

Regards

Liam

Link to comment
Share on other sites

<?php
session_start();

include("connect.php");

if (isset($_POST["Login"]))
{
$username = $_POST["username"];
$password = md5($_POST["password"]);

$result = mysql_query("select * from user where username = '$username';");
if(!$result)
{
	die("Error " . mysql_errno() . ": " . mysql_error());
}
$isExist = mysql_num_rows($result);


echo "<p>User supplied password: $password</p>\n";

while($row = mysql_fetch_assoc($result))
{
	echo "<pre>\n";
	print_r($row);
	echo "</pre>\n";
}



if ($isExist == 1)
{
		$_SESSION["username"] = $password;
		echo '<script>location.href="tutorials[1].php";</script>';

}
else
{
		echo '<script>alert("Invalid username or password!");
		history.go(-1);</script>';
}
}

else
{
		echo '<script>location.href="index.php";</script>';
}


?>

 

Try that and let us know what the output is.

Link to comment
Share on other sites

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.