-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
85 lines (76 loc) · 2.44 KB
/
add.php
File metadata and controls
85 lines (76 loc) · 2.44 KB
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
<?php
session_start();
if (!isset($_SESSION['name'])) {
die('Not logged in');
}
if (isset($_SESSION["name"])) {
if (isset($_POST["cancel"])) {
header("Location: view.php");
return;
}
if (isset($_POST["add"])) {
$_SESSION['errors'] = array();
// $make = htmlspecialchars($_POST['make']);
$make = htmlentities($_POST['make']);
$year = htmlentities($_POST['year']);
$mileage = htmlentities($_POST['mileage']);
if (strlen($make) == 0) {
$_SESSION['errors'][] = 'Make is required';
error_log('make field required');
}
if (!is_numeric($year) || !is_numeric($mileage)) {
$_SESSION['errors'][] = ' Mileage and year must be numeric';
error_log('Mileage and year must be numeric');
}
if (count($_SESSION['errors']) == 0) {
require_once "pdo.php";
$sql = "INSERT INTO misc.autos (make,year,mileage) values ('$make',$year,$mileage)";
$conn->exec($sql);
$_SESSION["success"] = "Record inserted";
header("Location: view.php");
return;
} else {
header("Location: add.php");
return;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>dc5d86e5</title>
</head>
<body>
<h3>Tracking Autos For <?php echo $_SESSION['name']; ?></h3>
<p style='color:green;'>
</p>
<p style='color:red'>
<?php
if (isset($_SESSION['errors'])) {
foreach ($_SESSION['errors'] as $value) {
echo htmlentities($value) . '<br>';
}
unset($_SESSION['errors']);
}
?>
</p>
<form action="" method="POST">
make:<br>
<input type="text" id="fname" name="make"><br>
year:<br>
<input type="text" id="lname" name="year"><br><br>
mileage<br>
<input type="text" name="mileage"><br><br>
<button type="submit" value="Add" name="add">Add</button>
<button type="submit" value="cancel" name="cancel">cancel</button>
</form>
</body>
</html>
<?php
} // else {
// die('Not logged in');
// }
?>