I had solved this and at home it worked, I made notes to myself based on what I did, took it to work with me and its not working. The code:
login page:
PHP Code:
<?php require_once('../Connections/connNative.php');
# start the session
session_start();
# define some useful variables
$redirect_success = 'clientArea_test.php';
$redirect_failure = 'failure_test.php';
# if the form has been submitted
if (isset($_POST['mm_login'])) {
mysql_select_db($database_connNative, $connNative);
$loginUsername = $_POST['username'];
$password = md5($_POST['pwd']);
# run login query
# select the field you require and the fields to be registered as session variables
$login = mysql_query("select client_id, username, pwd from clients where username = $loginUsername' and pwd = '$password'") or die (mysql_error());
$login_rows = mysql_fetch_assoc($login);
$login_check = mysql_num_rows ($login);
if($login_check >0) {
# now we can register the session variables
$_SESSION['client_id'] = $login_rows['client_id'];
$_SESSION['username'] = $login_rows['username'];
# NOTE. you can only register the field you have requested from database
# direct as appropriate
header ("Location: ". $redirect_success);
} else {
header ("Location: ". $redirect_fail);
}
}
?>
<!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>Login Client</title>
</head>
<body>
<form name="clientLogin" id="clientLogin" method="POST" action="<?php $_SERVER['../PHP_SELF']; ?>">
<table width="391" border="0">
<tr>
<td width="184">Username</td>
<td width="197"><input name="username" type="text" id="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input name="pwd" type="password" id="pwd" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Login" /></td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
client area:
PHP Code:
<?php require_once('../Connections/connNative.php');
# start the session
session_start();
# define variables from the session variables
$client_id = $_SESSION['client_id'];
mysql_select_db ($database_connNative, $connNative);
# run the query to get the info from the database
$client_sql = mysql_query("select * from clients where client_id = '$client_id'") or die (mysql_error());
$client_rows = mysql_fetch_assoc($client_sql);
?>
<!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>Client Area</title>
</head>
<body>
<? echo $client_rows['client']; ?>
</body>
</html>
Many thanks in advance.
Bookmarks