-
Notifications
You must be signed in to change notification settings - Fork 0
/
addgc.php
87 lines (68 loc) · 2.43 KB
/
addgc.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Garbage Collector</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<br><br>
<div class="container">
<h2>Add Garbage Collector</h2>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Name:</label>
<input type="text" class="form-control" placeholder="Enter Name" name="name">
</div>
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Enter Address" name="address">
</div>
<div class="form-group">
<label>Phone number:</label>
<input type="tel" class="form-control" name="phone" placeholder="Enter Phone Number" pattern="[0-9]{10}" maxlength="10" required>
</div>
</div>
<center> <input type="submit" name="insert-btn" class="btn btn-primary" /> </center>
<br><br>
<center> <a class="btn btn-primary" href="index.php">back to home</a> </center>
</form>
</div>
</body>
</html>
<?php
require 'config.php';
// if(mysqli_connect_errno()){
// echo "connection fail";
// }
// else{
// echo "connection success";
// }
if(!empty($_SESSION["id"])){
if (isset($_POST['insert-btn'])) {
$randomNum=substr(str_shuffle("0123456789"), 0, 3);
$idno = "GC".$randomNum;
$sv_id = $_SESSION["id"];
$gc_idno = $idno;
$gc_uname = $_POST['name'];
$gc_address = $_POST['address'];
$gc_phone = $_POST['phone'];
$insert = "INSERT INTO `gc_user`(`sv_id`,`gc_id`, `gc_name`, `gc_address`, `gc_phone`)
VALUES ('$sv_id','$gc_idno','$gc_uname','$gc_address','$gc_phone')";
$run_insert = mysqli_query($conn, $insert);
if ($run_insert == true) {
echo
"<script> alert('Data Inserted Successfully'); </script>";
} else {
"<script> alert('Failed, Try Again'); </script>";
}
}
}
else {
header("Location: login.php");
}
?>