Jump to content

Simple Login Script Help Needed


sjones

Recommended Posts

Hello, I am making a simple login script, and I can’t get the proper results from the query. I will post the code below. When I enter the username and password, I query the database for a match and it comes back that it does not match. I have gone to the phpmyadmin and changed the password several times to the same password that I am typing in. I have it in a password field in the database. I am wondering if the MySQL Collation has anything to do with it??

 

Could you please look at my code and see if you can find anything that may be interfering with positive results.

I have redone this script several times,

I have confirmed that the mysql_connect.php include is working.

I have looked at the error logs and below is the only error in there:

 

ERROR LOG

PHP Notice:  Undefined variable:  logged_in_user in /home/virtual/site11/fst/var/www/html/new2009/properties/index.php on line 13, referer: http://www.bdrycleveland.com/new2009/properties/index.php

 

I am suspecting the password field (Just a hunch)

 

Here is the code:

 

<?php  session_start() ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<?php  

if ($username && $password) {
	if ($logged_in_user == $username) {
		echo $username. ", you are already logged in.<br><br>";
		exit();
	}
	require_once ('../connections/mysql_connect.php');
	$result = mysql_query("SELECT * FROM user WHERE user_name = '".$username."' 
						   AND user_password = PASSWORD('".$password."')");
	if (!$result) {
		echo "Sorry, there has been a technical hitch. We cannot enter your details.";
		exit();
	}
	if (mysql_num_rows($result) >0 ) {
		$logged_in_user = $username;
		session_register("logged_in_user");
		echo "Welcome, ".$logged_in_user.".<br><br>";
		exit();
	} else {
		echo "Invalid login, Please try again.<br><br>";
	}

} else if ($username || $password) {
	echo "Please fill in both fields<br><br>";
}

?>

<form method="post" action="index.php">
<p>Username:<br><input name="username" type="text" size="12" maxlength="12"></p>
<p>Password:<br><input name="password" type="password" size="12" maxlength="12"></p>
<p><input name="submit" type="submit" value="Submit"></p>
</form>


</body>
</html>

 

The Database table is very simple also:

  Field                    Type              Collation              Attributes                Null Default    Extra Action        

   

  user_id              smallint(5)                            UNSIGNED ZEROFILL  No              auto_increment             

  user_name        varchar(12)  latin7_general_cs                              No                 

  user_password  varchar(12)  latin7_general_cs                              No                 

     

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/147660-simple-login-script-help-needed/
Share on other sites

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.