我的注册表单已停止工作,我感觉这与将php版本更新到7.3的主机有关,但不是100%确定,登录表单仍然可以正常工作,但仅注册表单无效,php编码在下面
<?php
// Include config file
require_once "registerconfig.php";
// Define variables and initialize with empty values
$customer_name = $username = $password = $confirm_password = "";
//$username = $password = $confirm_password = "";
$customer_name_err = $username_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate customer name
if(empty(trim($_POST["customer_name"]))){
$customer_name_err = "Please enter your name.";
} else{
// Prepare a select statement
$sql = "SELECT customer_name FROM users WHERE customer_name = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_customer_name);
// Set parameters
$param_customer_name = trim($_POST["customer_name"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$customer_name_err = "This Name is already taken.";
} else{
$customer_name = trim($_POST["customer_name"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Validate username
if(empty(trim($_POST["user_name"]))){
$username_err = "Please enter a username.";
} else{
// Prepare a select statement
$sql = "SELECT user_id FROM users WHERE user_name = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = trim($_POST["user_name"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$username_err = "This username is already taken.";
} else{
$username = trim($_POST["user_name"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Validate password
if(empty(trim($_POST["user_pass"]))){
$password_err = "Please enter a password.";
} elseif(strlen(trim($_POST["user_pass"])) < 6){
$password_err = "Password must have at least 6 characters.";
} else{
$password = trim($_POST["user_pass"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
} else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
}
// Check input errors before inserting in database
if(empty($customer_name_err) && empty($username_err) && empty($password_err) && empty($confirm_password_err)){
// Prepare an insert statement
$sql = "INSERT INTO users (user_name, user_pass, customer_name) VALUES (?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_username, $param_password, $param_customer_name);
// Set parameters
$param_customer_name = $customer_name;
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$to = "myemail@domain.co.uk";
$subject = "A new user has signed up";
$message = " <strong>$customer_name</strong> has just signed up on the website, below is their information<br /><br />
<u>Customer Details</u><br /><br><strong>Users Name</strong>: $customer_name<br><br><strong>Username</strong>: $username";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <noreply@domain.co.uk>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
// Redirect to login page
header("location: login.php?registered=success");
} else{
echo "Something went wrong. Please try again.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($link);
}
?>
<?php
//define page title
$title = 'Register';
$pgDesc="";
$pgKeywords="";
$canonical_url = "https://www.domain.co.uk/account/register";
//include header template
require('../includes/inner-header.php');
?>
<div class="col-xs-12 col-sm-12 col-md-6 centerform">
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" class="registrationform">
<div class="form-group <?php echo (!empty($customer_name_err)) ? 'has-error' : ''; ?>">
<label>Name</label>
<input type="text" name="customer_name" class="form-control input-lg" value="<?php echo $customer_name; ?>">
<span class="help-block"><?php echo $customer_name_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<label>Username</label>
<input type="text" name="user_name" class="form-control input-lg" value="<?php echo $username; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="user_pass" class="form-control input-lg" value="<?php echo $password; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control input-lg" value="<?php echo $confirm_password; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
<p>Already have an account? <a href="login">Login here</a>.</p>
</form>
</div>
</div>
</div>
</div>
<?php require('../includes/footer.php'); ?>
我看不到问题所在,因为页面上没有任何错误,除了说出问题了,请重试