2 Replies - 1422 Views - Last Post: 31 July 2008 - 09:34 PM Rate Topic: -----

#1 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Problem with PHP Login System

Posted 31 July 2008 - 08:36 PM

I seem to be having problems with this PHP login system. I got the registration to work, yet the login page resembles no result when attempting to load anything. The following is the code for the login page (without the db information):

<?
// Use session variable on this page. This function must put on the top of page.
session_start();

////// Logout Section. Delete all session variable.
session_destroy();

$message="";

////// Login Section.
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$md5_password=md5($_POST['password']); // Encrypt password with md5() function.

// Connect database.
$host="localhost"; // Host name.
$db_user="-----"; // MySQL username.
$db_password="-----"; // MySQL password.
$database="-------"; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

// Check matching of username and password.
$result=mysql_query("select * from admin where username='$username' and password='$md5_password'");
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username"); // Craete session username.
header("location:main.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}

} // End Login authorize check.
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<style type="text/css">
<!--
body {
	background-color: #000000;
}

width:99%;
}
-->
</style>
<body text="white">
<? echo $message; ?>
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table>
<tr>
<td>User : </td>
<td><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Password : </td>
<td><input name="password" type="password" id="password" /></td>
</tr>
</table>
<input name="Login" type="submit" id="Login" value="Login" />
</form>
</body>
</html> 



Could you find any problems with this? I have numerous other login pages that are different then this, yet none of them seem to work.

The result - when using this login page - is the following error (with db information removed):


Warning: mysql_query() [function.mysql-query]: Access denied for user 'advanco9'@'localhost' (using password: NO) in /-----/------/public_html/spomi/login1111/login.php on line 8

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /-----/---/public_html/spomi/login1111/login.php on line 8

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /----/-----/public_html/spomi/login1111/login.php on line 9
Error: Username or password was incorrect.


Could you assist?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with PHP Login System

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5379
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Problem with PHP Login System

Posted 31 July 2008 - 08:39 PM

Your 1st error message says it all.

Quote

Warning: mysql_query() [function.mysql-query]: Access denied for user 'advanco9'@'localhost' (using password: NO) in /-----/------/public_html/spomi/login1111/login.php on line 8


You need to either grant the user advanco9 with the required privileges, or correct the login information you are supplying.

Since using password is set to NO, my guess is, this needs to be yes. However, since I don't know how you setup your mysql, I can't tell you what it should be.
Was This Post Helpful? 0
  • +
  • -

#3 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Re: Problem with PHP Login System

Posted 31 July 2008 - 09:34 PM

Actually it was just a problem with quotes. I was talking to someone and got it fixed. Thanks anyway.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1