-1
我上傳了一個登錄/註冊網站Godaddy出於某種原因頁面將不能正確重定向,它可以在本地主機上正常測試,任何幫助將不勝感激!頁面將不會重定向到正確的頁面
這是我的register.php頁面代碼:你header()
調用之前
<!doctype html>
<html lang="en">
<head>
<title>Register page</title>
<meta charset=utf-8>
<link rel="stylesheet" type="text/css" href="includes.css">
<style type="text/css">
p.error { color:red; font-size:105%; font-weight:bold; text-align:center;}
</style>
</head>
<body>
<div id="container">
<?php include("register-header.php"); ?>
<?php include("nav.php"); ?>
<?php include("info-col.php"); ?>
<div id="content"><!-- Start of the register page content -->
<p><?php
require ('mysqli_connect.php'); // Connect to the database.
// If the form has been submitted, insert a record in the users table
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$errors = array(); // Initialize an error array
// Check for a first name:
if (empty($_POST['fname'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
//$fn = trim($_POST['fname']);
$fn = mysqli_real_escape_string($dbcon, trim($_POST['fname']));
}
// Check for a last name:
if (empty($_POST['lname'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
//$ln = trim($_POST['lname']);
//$ln = mysqli_real_escape_string($dbcon, $ln);
$ln = mysqli_real_escape_string($dbcon, trim($_POST['lname']));
}
// Check for an email address
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = trim($_POST['email']);
}
// Check for a password then match it against the confirmed password:
if (!empty($_POST['psword1'])) {
if ($_POST['psword1'] != $_POST['psword2']) {
$errors[] = 'Your two password did not match.';
} else {
$p = mysqli_real_escape_string($dbcon, trim($_POST['psword1']));
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) { // If everything's OK
// Register the user in the database...
// Make the query:
$q = "INSERT INTO users (user_id, fname, lname, email, psword, registration_date) VALUES (' ', '$fn', '$ln', '$e', SHA1('$p'), NOW())";
$result = @mysqli_query ($dbcon, $q); // Run the query.
if ($result) { // If it ran OK
header ("location: register-thanks.php");
exit();
// Echo a message:
//echo '<h2>Thank you!</h2>
//<p>You are now registered.</p><p><br></p>';
} else { // If it did not run OK
// Error message:
echo '<h2>System Error</h2>
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
} // End of if ($result)
mysqli_close($dbcon); // Close the database connection.
// Include the footer and stop the script
include ('footer.php');
//header ("location: register-thanks.php");
//exit();
} else { // Report the errors
echo '<h2>Error!</h2>
<p class="error">The following error(s) occurred:<br>';
foreach ($errors as $msg) { // Echo each error
echo " - $msg<br>\n";
}
echo '</p><h3>Please try again.</h3><p><br></p>';
}// End of if (empty($errors))
} // End of the main Submit conditional
?>
<h2>Register</h2>
<form action="register-page.php" method="post">
<p><label class="label" for="fname">First Name:</label><input id="fname" type="text" name="fname" size="30" maxlength="30" value="<?php if (isset($_POST['fname'])) echo $_POST['fname']; ?>"></p>
<p><label class="label" for="lname">Last Name:</label><input id="lname" type="text" name="lname" size="30" maxlength="40" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>"></p>
<p><label class="label" for="email">Email Address:</label><input id="email" type="text" name="email" size="30" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" > </p>
<p><label class="label" for="psword1">Password:</label><input id="psword1" type="password" name="psword1" size="12" maxlength="12" value="<?php if (isset($_POST['psword1'])) echo $_POST['psword1']; ?>" > Between 8 and 12 characters.</p>
<p><label class="label" for="psword2">Confirm Password:</label><input id="psword2" type="password" name="psword2" size="12" maxlength="12" value="<?php if (isset($_POST['psword2'])) echo $_POST['psword2']; ?>" ></p>
<p><input id="submit" type="submit" name="submit" value="Register"></p>
</form>
<?php include ('footer.php'); ?></p>
<!-- End of the register page content -->
</div>
</div>
</body>
</html>
打開錯誤報告,它可能會給你一個提示。另外,當你遇到困難時,嘗試創建一個能夠重現問題的最小例子。在這種情況下,如果你試圖做一個重定向,你會發現它的工作原理。所以,這個問題是別的......開始隔離和測試。你在這裏做的是在我們身上扔了一大堆代碼,然後說:「爲什麼它沒有做我想要的?」 - 你永遠不會像這樣學習。 – 2014-09-18 16:54:08