/
category.php
59 lines (50 loc) · 1.33 KB
/
category.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
<?php
session_start();
if(!$_SESSION["logged_in"]){
header("location:home.php");
die;
}
?>
<?php
// Only process the form if $_POST isn't empty
if ( ! empty( $_POST ) ) {
// Connect to MySQL
$mysqli = new mysqli( 'localhost', 'root', 'root', 'w_c_a' );
// Check our connection
if ( $mysqli->connect_error ) {
die( 'Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
// Insert our data
$sql = "INSERT INTO category (description) VALUES ( '{$mysqli->real_escape_string($_POST['description'])}' )";
$insert = $mysqli->query($sql);
// Print response from MySQL
if ( $insert ) {
header("location:vehicles.php");
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}
// Close our connection
$mysqli->close();
}
?>
<?php include 'header.php' ?>
<div id="maincontent">
<form method="post" action="">
<input name="description" type="text">
<input type="submit" value="Submit New Category">
</form>
<?php
require_once('config.php');
$query = "SELECT * FROM category";
$results = mysql_query($query, $conn);
if (!$results) {
die ("Error selecting car data: " .mysql_error());
}
else {
while ($row = mysql_fetch_array($results)) {
echo "<p> $row[description] </p>";
}
}
?>
<a href="vehicles.php">Back to Vehicles</a>
<?php include 'footer.php' ?>