Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re-directing a page?

Status
Not open for further replies.

biscuitboy

Technical User
Dec 11, 2004
22
0
0
GB
Hiya,

The following script I am using as a login screen and it seems to work fine apart from where the user is meant to be sent to the surname.php page. Have I written this incorrectly?

Any advice would be great

Best regards

Code:

<?php # Scrtipt 6.6 - viewresidents.php
if (isset($_GET['submit'])) {
require_once ('connect.php');

$message = NULL;
if (empty($_GET['username'])) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = $_GET['username'];
}
if (empty($_GET['password'])) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
$p = $_GET['password'];
}

if ($u && $p) { //if everythings ok
$query = "SELECT first_name, user_id FROM users WHERE username='$u' AND password='$p'";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) {
//start session, register the values and redirect
session_start();
$_SESSION['first_name'] = $row[1];
$_SESSION['user_id'] = $row[0];
header ("location: . $_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) . "/surname.php");

exit();

} else {
$message = '<p>The username and password entered do not match those on the file.</p>';
}
mysql_close();
} else {
$message .= '<p>Please try again.</p>';
}
}
$page_title = 'Login';
if (isset($message)) {
echo '<font color="red">',$message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>User Name:</b><input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p><b>Password:</b><input type="password" name="password" size="20" maxlength="20" /></p>
<div align="centre"><input type="submit" name="submit" value="Login" /></div>
</form><!-- end of form -->
 
looks ok. try debugging by creating the redirect href in a string and instead of redirecting echo the string to the screen. this is the most likely point of error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top