cyberfreek
IS-IT--Management
below is a problem I have had with access in mysql. Thank you in advance.
I re-installed MySQL and didnt give root any password. This is the stage I am at right now.
When I am in the MYSQL monitor what I do is :
mysql> use mysql
mysql> SELECT host, user, password FROM user;
the result is a table that gives
host user password
localhost root
%
localhost root
%
....so in my PHP code I keep it at
*******
PHP
******
<?
// login.php - performs validation
// authenticate using form variables
$status = authenticate($f_user, $f_pass);
// if user/pass combination is correct
if ($status == 1)
{
// initiate a session
session_start();
// register some session variables
session_register("SESSION"
;
// including the username
session_register("SESSION_UNAME"
;
$SESSION_UNAME = $f_user;
// redirect to protected page
header("Location: ../content/jobs/job1.php"
;
exit();
}
else
// user/pass check failed
{
// redirect to error page
header("Location: ../errors/loginError.php?e=$status"
;
exit();
}
// authenticate username/password against a database
// returns: 0 if username and password is incorrect
// 1 if username and password are correct
function authenticate($user, $pass)
{
// configuration variables
// normally these should be sourced from an external file
// for example: include("dbconfig.php"
;
// variables explicitly set here for illustrative purposes
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "dgi";
// check login and password
// connect and execute query
$connection = mysql_connect($db_host, $db_user, $db_pass) or die
("Unable FIRST ERROR ON LOGIN to connect to the Database!"
;
$query = "SELECT id FROM resumes WHERE username = '$user' AND
password = PASSWORD('$pass')";
mysql_select_db($db_name);
$result = mysql_query($query, $connection) or die ("Error SECOND
ERROR ON
LOGIN in
query: $query. " . mysql_error());
// if row exists -> user/pass combination is correct
if (mysql_num_rows($result) == 1)
{
return 1;
}
// user/pass combination is wrong
else
{
return 0;
}
}
?>
****
MySQL
*****
I have a DB names dgi with only 1 table called resumes with 3 records
id INT,
username varChar(30),
password varChar(30)
I then inserted 1 person
INSERT INTO resumes VALUES (1, 'trevor' , 'niblock' );
and when I look at those they are all fine in the DB.
What I am trying to say is that I have total control in MySQL monitor
and I dont see any mistake at loginError.php
*******
login.php
*********
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
echo "Error Page if you user/password comboo failed at login.php" ;
?>
</body></html>
SO I THINK ITS OBIVOUSLY TO DO WITH THE SESSION CONTROL RETURNING
A 0 AS IT DOESNT THINK THAT F_USER & F_PASS EXSIT WHEN THEY DDO
EXIST AND CORRESPOND TO THE DB.
I re-installed MySQL and didnt give root any password. This is the stage I am at right now.
When I am in the MYSQL monitor what I do is :
mysql> use mysql
mysql> SELECT host, user, password FROM user;
the result is a table that gives
host user password
localhost root
%
localhost root
%
....so in my PHP code I keep it at
*******
PHP
******
<?
// login.php - performs validation
// authenticate using form variables
$status = authenticate($f_user, $f_pass);
// if user/pass combination is correct
if ($status == 1)
{
// initiate a session
session_start();
// register some session variables
session_register("SESSION"
// including the username
session_register("SESSION_UNAME"
$SESSION_UNAME = $f_user;
// redirect to protected page
header("Location: ../content/jobs/job1.php"
exit();
}
else
// user/pass check failed
{
// redirect to error page
header("Location: ../errors/loginError.php?e=$status"
exit();
}
// authenticate username/password against a database
// returns: 0 if username and password is incorrect
// 1 if username and password are correct
function authenticate($user, $pass)
{
// configuration variables
// normally these should be sourced from an external file
// for example: include("dbconfig.php"
// variables explicitly set here for illustrative purposes
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "dgi";
// check login and password
// connect and execute query
$connection = mysql_connect($db_host, $db_user, $db_pass) or die
("Unable FIRST ERROR ON LOGIN to connect to the Database!"
$query = "SELECT id FROM resumes WHERE username = '$user' AND
password = PASSWORD('$pass')";
mysql_select_db($db_name);
$result = mysql_query($query, $connection) or die ("Error SECOND
ERROR ON
LOGIN in
query: $query. " . mysql_error());
// if row exists -> user/pass combination is correct
if (mysql_num_rows($result) == 1)
{
return 1;
}
// user/pass combination is wrong
else
{
return 0;
}
}
?>
****
MySQL
*****
I have a DB names dgi with only 1 table called resumes with 3 records
id INT,
username varChar(30),
password varChar(30)
I then inserted 1 person
INSERT INTO resumes VALUES (1, 'trevor' , 'niblock' );
and when I look at those they are all fine in the DB.
What I am trying to say is that I have total control in MySQL monitor
and I dont see any mistake at loginError.php
*******
login.php
*********
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
echo "Error Page if you user/password comboo failed at login.php" ;
?>
</body></html>
SO I THINK ITS OBIVOUSLY TO DO WITH THE SESSION CONTROL RETURNING
A 0 AS IT DOESNT THINK THAT F_USER & F_PASS EXSIT WHEN THEY DDO
EXIST AND CORRESPOND TO THE DB.