-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
80 lines (65 loc) · 1.83 KB
/
index.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
<?php
require_once("pdo.php"); //require pdo.php to connect to the database
Session_start();
?>
<!DOCTYPE=htm>
<html>
<head>
<title>Simran Gosai Index Page</title>
<body>
<h1> Welcome to the Automobiles Database</h1>
<p>
<?php
// php code to check if logged in
if (! isset($_SESSION["email"]) ) {
echo "<p><a href=\"login.php\"> Please log in </a></p>";
echo "<p>Attempt to <a href=\"add.php\">Add data </a> without logging in.</p>";
}
if ( isset($_SESSION['error']) ) {
echo '<p style="color:red">'.$_SESSION['error']."</p>\n";
unset($_SESSION['error']);
}
if ( isset($_SESSION['success']) ) {
echo '<p style="color:green">'.$_SESSION['success']."</p>\n";
unset($_SESSION['success']);
}
if (isset($_SESSION["email"]) ) {
$stmt = $pdo->query("SELECT make, model, year, mileage, autos_id FROM autos");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (isset($row["autos_id"]) ) {
echo('<table border="1">'."\n");
echo "<tr><td>";
echo "<b>Make</b>";
echo "</td><td>";
echo "<b>Model</b>";
echo "</td><td>" ;
echo "<b>Year</b>";
echo "</td><td>";
echo "<b>Mileage</b>";
echo "</td><td>";
echo "<b>Action</b>";
echo "</td><td></tr>";
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
echo "<tr><td>";
echo(htmlentities($row['make']));
echo("</td><td>");
echo(htmlentities($row['model']));
echo("</td><td>");
echo(htmlentities($row['year']));
echo("</td><td>");
echo(htmlentities($row['mileage']));
echo("</td><td>");
echo('<a href="edit.php?autos_id='.$row['autos_id'].'">Edit</a> / ');
echo('<a href="delete.php?autos_id='.$row['autos_id'].'">Delete</a>');
echo("</td></tr>\n");
}
}
else{
echo "<p>no rows found</p>";}
echo "<p><a href=\"add.php\">Add New Entry</a></p>";
echo "<p><a href=\"logout.php\">Logout</a></p>";
}
?>
</body>
</head>
</html>