注册后想要将用户引导至他们的帐户

时间:2016-01-31 02:10:04

标签: javascript php redirect header

只需创建一个简单的注册表单,并希望我们的用户在注册后直接进入他们的帐户页面。但是我遇到问题,因为信息将存储在数据库中,但页面不会被定向。

<?php
session_start();
include "php/config/database.php";

if (isset($_POST['submit'])) {
    $FirstName = $_POST['FirstName'];
    $Surname   = $_POST['Surname'];
    $Email     = $_POST['Email'];
    $Password  = $_POST['Password'];

    // Check if data exists already in the database

    $exists  = mysqli_query($conn, "SELECT Email FROM Users WHERE Email = '$Email'");
    $row     = mysqli_fetch_array($exists);
    $dbEmail = $row['Email'];
    if ($Email == $dbEmail) {
        die("Email already taken.");
    }
}

$registerUser = "INSERT INTO Users(FirstName,Surname,Email,Password)VALUES('$FirstName','$Surname','$Email','$Password')"; { // Select ID from registered user
    $selectID           = "SELECT UserID FROM Users WHERE Email = '$Email'";
    $selectID_Query     = mysqli_query($conn, $selectID);
    $fetch              = mysqli_fetch_array($selectID_Query);
    $userID = mysqli_insert_id($conn);
    $userID             = $fetch['UserID'];
    $_SESSION['UserID'] = $UserID;
    if (mysqli_query($conn, $registerUser)) {
        header("Location: account.php");
    } else {
        echo "<script>alert('error while registering you...');</script>";
    }
}
?>
<html>
<head> 
  <meta charset="UTF-8">
    <title>background</title>
 </head>
  <body>

</body>
</html>

1 个答案:

答案 0 :(得分:-1)

尝试:

if (mysqli_query($conn, $registerUser)) {
    <script>window.location = "http://www.yoururl.com/path/to/account.php";</script>
  } else {
    echo "<script>alert('error while registering you...');</script>";
}