-
Notifications
You must be signed in to change notification settings - Fork 0
/
customerReg.php
executable file
·219 lines (184 loc) · 6.66 KB
/
customerReg.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
// Include config file
require_once "dbconfig.php";
error_reporting(E_ERROR);
// Define variables and initialize with empty values
$username = $mpesa = $amount = $password = $confirm_password = $sweet = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST['username']) || empty($_POST['mpesa']) || empty($_POST['amount']) || empty($_POST['password']) || empty($_POST['confirm_password'])){
$sweet = 'error';
$feedback = 'Please enter all registration details';
}
// Validate username
if(empty(trim($_POST["username"]))){
$sweet = 'error';
$feedback = 'Enter a Username.';
} else{
// Prepare a select statement
$sql = "SELECT id FROM users WHERE username = ?";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = trim($_POST["username"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$sweet = 'error';
$feedback = 'This username is already taken try another';
} else{
$username = trim($_POST["username"]);
}
} else{
$feedback = 'Oops! Something went wrong. Please try again later 1.';
}
}
// Close statement
mysqli_stmt_close($stmt);
}
//Validate mpesa code
if(empty(trim($_POST["mpesa"]))){
$sweet = 'error';
$feedback = 'Please pay up a registration fee of 100 ksh and enter the transaction code to register with Mafundi Services';
} elseif(strlen(trim($_POST["mpesa"])) < 10){
$sweet = 'error';
$feedback = 'Please Enter A Valid Mpesa transaction Code.';
} else{
$mpesa = trim($_POST["mpesa"]);
}
//Validate amount
if(empty(trim($_POST["amount"]))){
$sweet = 'error';
$feedback = 'Please enter the amount sent.';
} elseif(trim($_POST["amount"]) != 100){
$sweet = 'error';
$feedback = 'We only accept 100 shillings, if you paid in excess go to your dash board and request for a refund';
} else{
$amount = trim($_POST["amount"]);
}
// Validate password
if(empty(trim($_POST["password"]))){
$sweet = 'error';
$feedback = 'Please enter a valid password.';
} elseif(strlen(trim($_POST["password"])) < 6){
$sweet = 'error';
$feedback = 'Password must have atleast 6 characters.';
} else{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$sweet = 'error';
$feedback = 'Please confirm your password.';
} else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($sweet) && ($password != $confirm_password)){
$sweet = 'error';
$feedback = 'Your Password did not match, please try again.';
}
}
// Check input errors before inserting in database
if(empty($sweet)){
// Prepare an insert statement
$sql = "INSERT INTO users (username, mpesa, amount, password) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ssss", $param_username, $param_mpesa, $param_amount, $param_password);
// Set parameters
$param_username = $username;
$param_mpesa = $mpesa;
$param_amount = $amount;
$param_password = password_hash($password, PASSWORD_DEFAULT);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
$sweet = "success";
$feedback = "Your Request Will Be Processed Shortly, Please Wait A While And Try To Log In to your Account.";
} else{
$sweet = 'error';
$feedback = "Something went wrong. Please try again later.2";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Client Registration | Mafundi</title>
<!-- Bootstrap Stylesheet -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- sweet alert -->
<link rel="stylesheet" href="css/sweetalert.css">
<script src="js/sweetalert.js"></script>
<script src="js/jquery.js"></script>
<!-- FontAwesome -->
<link rel="stylesheet" href="css/all.min.css" />
<link rel="stylesheet" href="css/fontawesome.min.css" />
<!--Animate Css-->
<link rel="stylesheet" href="css/animate.min.css">
<!-- Css -->
<link rel="stylesheet" href="css/customerlogin.css">
<link rel="stylesheet" href="css/custreg.css">
</head>
<body>
<main>
<?php
// $sweet = "";
if($sweet == 'error'){
echo '<script>swal("Error", "'.$feedback.'", "error")</script>';
}elseif($sweet == 'success'){
echo '<script>swal("Success", "'.$feedback.'", "success")</script>';
}
?>
<a href="a.home.php"><img src="img/logo.png" alt=""></a>
<div class="card bg-transparent text-light mb-4 animated bounceInDown delay 3s">
<div class="card-body">
<h2 class="card-title">Client Registration Form.</h2>
<div class="card-text">
<p id="">Please fill in your credentials to register with mafundi services.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control" placeholder="Username..." value="<?php echo $username; ?>">
</div>
<div class="form-group">
<label>Mpesa Transaction Code</label>
<input type="text" name="mpesa" class="form-control" placeholder="Transaction Code..." value="<?php echo $mpesa; ?>">
</div>
<div class="form-group">
<label>Amount Paid/Sent</label>
<input type="text" name="amount" class="form-control" placeholder="Amount..." value="<?php echo $amount; ?>">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" value="<?php echo $password; ?>">
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control" placeholder="Confirm Password..." value="<?php echo $confirm_password; ?>">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-default" value="Reset">
</div>
<p id="">Already have an account? <a href="customerlogin.php">Login here</a>.</p>
</form>
</div>
<p class="futa">All Rights Reserved Copyrights © mafundiservices 2019.</p>
</div>
</div>
</div>
</main>
<!--Optional Javascript-->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>