lee101
VIP Member
As the title says i am getting myself more and more confused, i am trying to create a login script that will give access to an admin panel, it needs to check that the user and password are correct, then see if the admin_rights for that column is 1, which sounds fine, but i just keep getting more and more confused with more and more lines of code.
This is the code i currently have:
It is mainly the top 20-30 lines that i can't get working
and this is the error i get:
This is really confusing me, it is the first time i have used mysql, and everything seemed to be going well, the tutorial i am following tries to explain how to do this, but i cannot make any sense from it, and nothing like this seems to be anywhere on the web
Thanks, Lee
This is the code i currently have:
PHP:
<?php
include('../config.php');
//get variables
$action=$_POST['action'];
$user=$_POST['user'];
$pass=$_POST['pass'];
$md5_pass=md5($pass);
$user='user';
//perform login
if($action == "login"){
mysql_connect($cfg_db_host,$cfg_db_user,$cfg_db_pass);
@mysql_select_db($cfg_db_name) or die("Unable To Write Tables, Please Check Settings");
#$query_login="SELECT * FROM $cfg_db_prefix$user WHERE username='$user'";
$query_login="SELECT COUNT(*) FROM $cfg_db_prefix$user WHERE password=`$md5_pass` AND username=`$user` AND admin_rights=`1`";
$aaa=mysql_query($query_login);
$login_user=mysql_result($aaa,0);
echo $login_user;
echo mysql_error();
mysql_close();
} else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Install</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
include('header.inc.php');
?>
<div id="mainbody" style="width:300px;">
<h3>Administrator Login</h3>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="action" value="login" />
<table border="0" align="center" cellpadding="2" cellspacing="1">
<tr>
<td>Username</td>
<td><input type="text" name="user" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" name="pass" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
}
?>
and this is the error i get:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in c:\web\htdocs\tutorial_management_system\admin\index.php on line 16
Unknown column 'b07805d5ce7b71f5e3c7cd03124a081c' in 'where clause'
This is really confusing me, it is the first time i have used mysql, and everything seemed to be going well, the tutorial i am following tries to explain how to do this, but i cannot make any sense from it, and nothing like this seems to be anywhere on the web
Thanks, Lee