/
action.php
102 lines (74 loc) · 3.37 KB
/
action.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
//-----------------------------------------------------Processing SQL Database queries--------------------------------------------------------
function database ($sql, $h_success, $h_fail)
{
$servername = "localhost";
$username = "root";
$password = "College@2015";
$dbname = "ESPDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($conn->query($sql) === TRUE) {
echo "User Successfully Registered";
header($h_success);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$msg = "<br>Error: " . "<br>" . $conn->error;
$h_fail = $h_fail . "?msg=" . $msg;
header($h_fail);
exit();
}
$conn->close();
}
//-------------------------------------------------------------Register Customer -------------------------------------------------------
function register($firstname, $middlename, $lastname, $email, $dob, $phone=NULL, $addrl1, $addrl2, $city, $state, $country, $zipcode){
$sql = "INSERT INTO customer (f_nm, m_nm, l_nm, email, dob, phone, street, adr_l2, city, state, country, zipcode, cr_dt)
VALUES ('$firstname', '$middlename', '$lastname', '$email', '$dob', '$phone', '$addrl1', '$addrl2', '$city', '$state', '$country', '$zipcode', now());";
$h_success = "Location:reg_success.html";
$h_fail = "Location:reg_fail.php";
database($sql,$h_success, $h_fail);
}
//------------------------------------------------------------ Create Customer id ----------------------------------------------------------
function create_user($email, $passwd, $repasswd, $firstname, $middlename, $lastname)
{
if (strcmp($passwd, $repasswd) !== 0) {
die("Password and Re-Enter Password is not equal");
}
$sql = "INSERT INTO user001 (ur_id, password, f_nm, m_nm, l_nm, cr_dt, cr_by)
VALUES ('$email', '$passwd', '$firstname', '$middlename', '$lastname', now(), current_user());";
$h_success = "Location:reg_success.html";
$h_fail = "Location:reg_fail.php";
$servername = "localhost";
$username = "root";
$password = "College@2015";
$dbname = "ESPDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($conn->query($sql) === TRUE) {
echo "User Successfully Registered";
register($_POST[firstname], $_POST[middlename], $_POST[lastname], $_POST[email], $_POST[dob], $_POST[phone], $_POST[addr1], $_POST[addr2], $_POST[city], $_POST[state], $_POST[country], $_POST[postalCode]);
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$msg = "Error: " . "<br>" . $conn->error;
$h_fail = $h_fail . "?msg=" . $msg;
header($h_fail);
exit();
}
$conn->close();
}
//---------------------------------------------------------------Function Calls--------------------------------------------------------------
if ($_POST[register])
{
create_user($_POST[email], $_POST[pass1], $_POST[pass2],$_POST[firstname], $_POST[middlename], $_POST[lastname]);
//register($_POST[firstname], $_POST[middlename], $_POST[lastname], $_POST[email], $_POST[dob], $_POST[phone], $_POST[addr1], $_POST[addr2], $_POST[city], $_POST[state], $_POST[country], $_POST[postalCode]);
}
//-------------------------------------------------------- End of Function Calls ------------------------------------------------------------
?>