-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
171 lines (134 loc) · 4.7 KB
/
add.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
<?php
ob_start();
@session_start();
?>
<html>
<head>
<title>Add Users</title>
<!-- Bootstrap CSS
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> -->
</head>
<body>
<div class="container">
<!-- <a href="index.php" class='btn btn-primary btn-sm' role='button' >Go to Home</a> -->
<div class="card-header">
<?php
// Check If form submitted, insert form data into users table.
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$phone_2 = $_POST['phone_2'];
$country = $_POST['country'];
$city = $_POST['city'];
$district = $_POST['district'];
// include database connection file
include_once("config.php");
// // Insert user data into table
$res= mysqli_query($mysqli, "SELECT*FROM users WHERE email='$email'");
$checkEmailExist=mysqli_num_rows($res);
if($checkEmailExist>0){
//return print_r( $checkEmailExist);
//exit;
$_SESSION['error']="Email for this user exists ";
return header('Location:index.php');
}
$result = mysqli_query($mysqli, "INSERT INTO users(name,email,address,phone,phone_2,country,city,district) VALUES('$name','$email','$address','$phone','$phone_2','$country','$city','$district')");
if($result){
// echo "User added successfully . ";
$_SESSION['success']="User added successfully ";
header('Location:index.php');
}else{
$_SESSION['error']="User not added ";
header('Location:index.php');
}
}
?>
</div>
<div class="card-body">
<form action="add.php" method="post" name="form1">
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">User form</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-row">
<div class="form-group col-md-6">
<label for="firstname">name</label>
<input type="text" class="form-control" name="name" id="firstname" placeholder="name" value="" required>
</div>
<div class="form-group col-md-6">
<label for="email">E-mail</label>
<input type="email" class="form-control" name="email" id="email" placeholder="email" value="" required>
</div>
<div class="form-group col-md-6">
<label for="workshop">Address</label>
<input type="text" class="form-control" name="address" id="address" placeholder="address" value="" required>
</div>
<div class="form-group col-md-6">
<label for="phone">Phone</label>
<input type="number" class="form-control" name="phone" id="phone" placeholder="phone" value="" required>
</div>
<div class="form-group col-md-6">
<label for="phone">Phone-2</label>
<input type="number" class="form-control" name="phone_2" id="phone_2" placeholder="phone-2" value="" required>
</div>
<div class="form-group col-md-6">
<label for="country">Country</label>
<select class="form-control" id="country" name="country" value="" required>
<option>Tanzania</option>
<option>Uganda</option>
<option>kenya</option>
<option>Rwanda</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="city">City</label>
<select class="form-control" id="city" name="city" value="" required>
<option>Dar-es-salaam</option>
<option>Mwanza</option>
<option>Dodoma</option>
<option>Singida</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="district">District</label>
<select class="form-control" id="district" name="district" value="" required>
<option>Temeke</option>
<option>Ilala</option>
<option>Kinondoni</option>
<option>Kigamboni</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class='btn btn-danger btn-sm' data-dismiss="modal">Close</button>
<button type="submit" name="Submit" value="Add" class='btn btn-success btn-sm' role='button' > Add</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
</div>
</div>
</table>
</form>
</div>
</div>
</body>
<?php
session_unset();
?>
</html>