-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.php
More file actions
55 lines (50 loc) · 2.2 KB
/
registration.php
File metadata and controls
55 lines (50 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// Detect the current session
session_start();
$MainContent = "";
// Read the data input from previous page
$name = $_POST["name"];
$birthDate = $_POST["birthDate"];
$address = $_POST["address"];
$country = $_POST["country"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$password = password_hash($_POST["password"], PASSWORD_DEFAULT);
$pwdQuestion = $_POST["pwdQuestion"];
$pwdAnswer = $_POST["pwdAnswer"];
$activeStatus = 1;
//setting timezone to singapore, date format is year/month/date (following database)
$todaysDate = new DateTime('now', new DateTimeZone('Asia/Singapore'));
$dateEntered = $todaysDate->format('Y-m-d\TH:i:s');
// Include the PHP file that establishes database connection handle: $conn
include_once("mysql_conn.php");
// Define the INSERT SQL statement
$qry = "INSERT INTO Shopper (Name, BirthDate, Address, Country, Phone, Email, Password, PwdQuestion, PwdAnswer, ActiveStatus, DateEntered)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($qry);
// "ssssss" - 6 string parameters
$stmt->bind_param("sssssssssis", $name, $birthDate, $address, $country, $phone, $email, $password, $pwdQuestion, $pwdAnswer, $activeStatus, $dateEntered);
if ($stmt->execute()) { // SQL statement executed successfully
// Retrive the Shopper ID assigned t the new shopper
$qry = "SELECT LAST_INSERT_ID() AS ShopperID";
$result = $conn->query($qry);
while ($row = $result->fetch_array()) {
$_SESSION["ShopperID"] = $row["ShopperID"];
}
// Display successful message and shopper ID
$MainContent = "<h3 style='text-align:center; color:green'>Registration successful</h3><br>";
//$MainContent .= "Registration successful!<br/>";
$MainContent .= "<h3 style='text-align:center; color:green'>Your ShopperID is $_SESSION[ShopperID]</h3>";
// Save the shopper name in a session variable
$_SESSION["ShopperName"] = $name;
}
else { // Display error message
$MainContent .= "<h3 style='text-align:center; color:red'>Error in inserting recrod</h3>";
}
// Release the resoruce allocated for prepared statement
$stmt->close();
// Close database connection
$conn->close();
// Include the master template file for this page
include ("MasterTemplate.php");
?>