你好,现在我有这个问题:当我注册时,只有 index.php 页面显示出来,没有成功的提示信息。但是当注册完成后,我会被重定向到 index.php?msg=1,按我的理解这是正确的吗?
<?php
if (isset($_GET['msg'] == 1)) {
echo "You have successfully registered.";
}
require_once('connect.php');
$errors = array();
if (isset($_POST['submit'])) {
if(empty($_POST['username'])){ array_push($errors, 'You did not submit a username'); }
$old_usn = mysqli_query($connect, "SELECT id FROM users WHERE name = '".htmlentities($_POST['username'], ENT_QUOTES)."' LIMIT 1;") or die(mysqli_error());
if (mysqli_num_rows($old_usn) > 0) { array_push($errors, 'This username is already registered.'); }
if (sizeof($errors) == 0) {
$username = htmlentities($_POST['username'], ENT_QUOTES);
$email = htmlentities($_POST['email'], ENT_QUOTES);
mysqli_query($connect, "INSERT INTO users (name, hashed_pw, email, joined)
VALUES ('{$username}', '{$password1}', '{$email}', NOW());") or die ($connection_error);
header('Location: index.php?msg=1');
}
}
?>