-
Notifications
You must be signed in to change notification settings - Fork 0
/
addvehicles.php
90 lines (73 loc) · 2.53 KB
/
addvehicles.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
<?php include 'head&nav.php';?>
<div class="content" id="vehicle">
<h1>Add Vehicles</h1>
<form class="below" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Vehicle No. <input type="text" name="vehicleno" />
<br/><br/>
Driver <input type="text" name="driver" />
<br/><br/>
Route <input type="text" name="route" />
<br/><br/>
Type <select name="type">
<option value="Blue Bus">Blue Bus</option>
<option value="Mini Bus">Mini Bus</option>
</select>
<br/><br/>
Operational: <br/>
<label for="yes">Yes</label> <input id="yes" type="radio" name="operational" value="yes" /> <label for="no">No</label> <input id="no" type="radio" name="operational" value="no" />
<br/><br/>
<input style="float: left;" type="submit" /> <input type="reset" />
</form>
<br/><br/>
<?php
// define variables and set to empty values
$vehicleno = $driver = $route = $type = $operational = $location = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$vehicleno = test_input($_POST["vehicleno"]);
$driver = test_input($_POST["driver"]);
$route = test_input($_POST["route"]);
$type = test_input($_POST["type"]);
$operational = $_POST["operational"];
$location = "13.0963789, -59.5478358";
//SEND DATA TO DATABADE
$server = "localhost";
$user = "root";
$pwd = "";
//CONNECT TO DATABASE
$db = "bimtravel";
$con = mysqli_connect($server, $user, $pwd, $db);
$sql = "INSERT INTO vehicles (vehicle_no, driver, route, type, operational, location)
VALUES('$vehicleno', '$driver', '$route', '$type', '$operational', '$location') ";
$q = mysqli_query($con, $sql);
if(!$con || !$db ||!$q ){
die('Error: '.mysqli_error($con));
echo 'something went wrong';
}
else{
echo '
<div class="alert success">
<span class="closebtn" onclick="this.parentElement.style.display=\'none\';">×</span>
You have successfully added a new vehicle!
</div>
<script>
setTimeout(function () {
window.location.href= \'addvehicles.php\'; // the redirect goes here
},10000);
</script>
';
}
mysqli_close($con);
}
?>
<br/>
<br/>
</div>
</div>
</body>
</html>