Nuttz77
02-23-2007, 01:58 PM
Hey all,
Having trouble with a php login. The login process itself is not failing. I have a tbl_auth_user with the login info inside my database and it views it and authenticates perfectly, thanks to somebodies words of wisdom here. The issue I have is on successful login it goes to a blank screen and still looks as if its on the login page (still shows xxx.xxx/englogin.php). If anyone can let me know what I did wrong I would appreciate it!! :confused: Here is the page script::
<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'opendb.php';
include 'config.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM tbl_auth_user
WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: enggui.html');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
include 'closedb.php';
}
?>
<html>
<head>
<title>Engineering Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<center><img src="ABC_FOX Logos.JPG" width="156" height="44"></center>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000">
<?php echo $errorMessage; ?></font></strong></p>
<div align="center">
<?php
}
?>
</div>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
Having trouble with a php login. The login process itself is not failing. I have a tbl_auth_user with the login info inside my database and it views it and authenticates perfectly, thanks to somebodies words of wisdom here. The issue I have is on successful login it goes to a blank screen and still looks as if its on the login page (still shows xxx.xxx/englogin.php). If anyone can let me know what I did wrong I would appreciate it!! :confused: Here is the page script::
<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'opendb.php';
include 'config.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM tbl_auth_user
WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: enggui.html');
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
include 'closedb.php';
}
?>
<html>
<head>
<title>Engineering Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<center><img src="ABC_FOX Logos.JPG" width="156" height="44"></center>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000">
<?php echo $errorMessage; ?></font></strong></p>
<div align="center">
<?php
}
?>
</div>
<form action="" method="post" name="frmLogin" id="frmLogin">
<table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text" id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password" id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>