-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddcustomer.php
182 lines (143 loc) · 5.52 KB
/
addcustomer.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php include('config/constants.php'); ?>
<link rel="stylesheet" href="css/admin.css">
<title>SignUp - Customer</title>
<div class="main-content">
<div class="wrapper">
<h1 class="coloura">Sign Up Now</h1>
<br>
<h3 class="error">*required</h3>
<br>
<?php
if (isset($_SESSION['add'])) //Checking whether the SEssion is Set of Not
{
echo $_SESSION['add']; //Display the SEssion Message if SEt
unset($_SESSION['add']); //Remove Session Message
}
?>
<?php
//Checking if all the fields are filled
$full_nameErr = $usernameErr = $passwordErr = $emailErr = $addressErr = $phoneErr = "";
if (empty($_POST["full_name"])) {
$full_nameErr = "";
}
if (empty($_POST["username"])) {
$usernameErr = "";
}
if (empty($_POST["password"])) {
$passwordErr = "";
}
if (empty($_POST["email"])) {
$emailErr = "";
}
if (empty($_POST["address"])) {
$addressErr = "";
}
if (empty($_POST["phone"])) {
$phoneErr = "";
}
?>
<form action="" method="POST">
<table class="tbl-30">
<tr>
<td>Full Name: </td>
<td>
<input type="text" name="full_name" placeholder="Enter Your Name">
<span class="error">* <?php echo $full_nameErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td>Username: </td>
<td>
<input type="text" name="username" placeholder="Your Username">
<span class="error">* <?php echo $usernameErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td>Password: </td>
<td>
<input type="password" name="password" placeholder="Your Password">
<span class="error">* <?php echo $passwordErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td>Email: </td>
<td>
<input type="email" name="email" placeholder="Your Email ID">
<span class="error">* <?php echo $emailErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" placeholder="Your Address">
<span class="error">* <?php echo $addressErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td>Phone No</td>
<td>
<input type="number" name="phone" placeholder="Your Phone Number">
<span class="error">* <?php echo $phoneErr; ?></span>
<br><br>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="Sign Up" class="btn btn-secondary">
</td>
</tr>
</table>
</form>
</div>
</div>
<?php
//Process the Value from Form and Save it in Database
//Check whether the submit button is clicked or not
if ((isset($_POST['submit'])) and ((empty($_POST["full_name"])) or (empty($_POST["username"])) or (empty($_POST["password"])) or (empty($_POST["email"])) or (empty($_POST["address"])) or (empty($_POST["phone"])))) {
$_SESSION['add'] = "<div class='error'>Failed to Add Customer.</div>";
//Redirect Page to Add Admin
header("location:" . SITEURL . 'addcustomer.php');
} elseif (isset($_POST['submit'])) {
// Button Clicked
//echo "Button Clicked";
//1. Get the Data from form
$full_name = $_POST['full_name'];
$username = $_POST['username'];
$password = md5($_POST['password']); //Password Encryption with MD5
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
//2. SQL Query to Save the data into database
$sql = "INSERT INTO tbl_customer SET
customer_name='$full_name',
customer_username='$username',
customer_password='$password',
customer_email='$email',
customer_address='$address',
customer_phoneno='$phone'
";
//3. Executing Query and Saving Data into Datbase
$res = mysqli_query($conn, $sql); // or die(mysqli_connect_error());
//4. Check whether the (Query is Executed) data is inserted or not and display appropriate message
if ($res == TRUE) {
//Data Inserted
//echo "Data Inserted";
//Create a Session Variable to Display Message
$_SESSION['add'] = "<div class='success'>Customer Added Successfully.</div>";
//Redirect Page to Manage Admin
header("location:" . SITEURL . 'logincust.php');
} else {
//FAiled to Insert DAta
//echo "Faile to Insert Data";
//Create a Session Variable to Display Message
$_SESSION['add'] = "<div class='error'>Failed to Add Customer.</div>";
//Redirect Page to Add Admin
header("location:" . SITEURL . 'addcustomer.php');
}
}
?>