-
Notifications
You must be signed in to change notification settings - Fork 0
/
autos.php
73 lines (62 loc) · 1.78 KB
/
autos.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
<?php
session_start();
if (!isset($_SESSION['email']) && !isset($_SESSION['password'])) {
die("Name parameters missing");
}
if (isset($_POST['logout'])) {
header("location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nfor Clifford Yungong - Automobile Tracker</title>
</head>
<body>
<h1>Tracking Autos for <?php echo $_SESSION['email']; ?></h1>
<P style="color: red;" >
<?php
require_once("pdo.php");
if (isset($_POST['add'])) {
if (!is_numeric($_POST['mileage']) || !is_numeric($_POST['year'])) {
echo "Mileage and year must be numeric";
}elseif (empty($_POST['make'])) {
echo "Make is required";
}else {
$stmt = $pdo->prepare("INSERT INTO autos (make, year, mileage) VALUES (:mk, :yr, :mi)");
$stmt->execute(array(':mk'=>$_POST['make'], ':yr'=>$_POST['year'], ':mi'=>$_POST['mileage']));
$color = "green";
echo "<p style='color: $color;'>Record inserted</p>";
}
}
$sql = $pdo->query("SELECT * FROM autos");
$row = $sql->fetchAll(PDO::FETCH_ASSOC);
?></P>
<form method="POST">
<lable for="make">Make:</lable>
<input type="text" name="make" id="make"><br><br>
<label for="Mileage">Mileage:</label>
<input type="text" name="mileage" id="Mileage"><br><br>
<label for="year">Year:</label>
<input type="text" name="year" id="year"><br><br>
<button type="submit" name="add">Add</button>
<button type="submit" name="logout">Logout</button>
</form><br>
<h3>Automobiles</h3>
<p><?php
foreach ( $row as $ro ) {
echo "<b>.</b> ";
echo htmlspecialchars("<b>");
echo($ro['make']);
echo " ";
echo($ro['mileage']);
echo " ";
echo($ro['year']);
echo "<br>";
}
?></p>
</body>
</html>