-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostUpload.php
50 lines (40 loc) · 1.33 KB
/
postUpload.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
<?php
// Enables association between client/server
session_start();
if (!isset($_SESSION["loggedin"])) {
exit("Need to be logged in to post!");
}
$USERID = $_SESSION["id"];
$USERNAME = $_SESSION["username"];
// Database information
$DB_HOST = "localhost";
$DB_USER = "root";
$DB_PASS = "";
$DB_NAME = "db";
// Connect to database
$conn = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
// Check for error
if ($conn->connect_error) {
exit('Failed to connect to MySQL: ' . $conn->connect_error);
}
$CARYEAR = 0;
$CARMAKE = "";
$CARMODEL = "";
$PHOTOURL = "";
if (isset($_POST["year"])) {
$CARYEAR = $_POST["year"];
}
if (isset($_POST["make"])) {
$CARMAKE = $_POST["make"];
}
if (isset($_POST["model"])) {
$CARMODEL = $_POST["model"];
}
if (isset($_POST["img"])) {
$PHOTOURL = $_POST["img"];
}
$DATE = date('Y-m-d H:i');
$result = $conn->query("INSERT INTO posts (uploadedByUserID, uploadedByUsername, uploadDate, photoURL, carYear, carMake, carModel)
VALUES ('$USERID', '$USERNAME', '$DATE', '$PHOTOURL', '$CARYEAR', '$CARMAKE', '$CARMODEL')");
mysqli_close($conn);
header("Location:index.php?status=success");