2016-01-31 165 views
-1

只是創建一個簡單的註冊表單,並希望我的用戶在註冊後直接進入他們的帳戶頁面。但即時通訊有問題,因爲信息將被存儲在數據庫中,但頁面不會被引導。想要在註冊後將用戶引導到他們的帳戶

<?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> 
+0

http://php.net/manual/en/function.error-reporting.php - http://php.net/manual/en/mysqli.error .php –

+0

你的register_user查詢失敗 –

+0

你應該看看'real_escape_string' –

回答

-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>"; 
}