-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
39 lines (30 loc) · 1.04 KB
/
submit.php
File metadata and controls
39 lines (30 loc) · 1.04 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
<?php
include 'config.php';
$title = $_POST['title'];
$description = $_POST['description'];
$ingredients = $_POST['ingredients'];
$instructions = $_POST['instructions'];
$category = $_POST['category'];
$user_id = $_POST['user_id'];
$sender = $_POST['sender'];
$filename = $_FILES["uploadfile"]["name"];
$tempname = $_FILES["uploadfile"]["tmp_name"];
$folder = "./uploads/" . $filename;
$sql = "INSERT INTO Submissions (title, description, ingredients, instructions, category, sender, user_id, image)
VALUES ('$title', '$description', '$ingredients', '$instructions', '$category', '$sender', '$user_id', '$filename')";
$response = array();
if (move_uploaded_file($tempname, $folder)) {
$response['imageUploaded'] = true;
} else {
$response['imageUploaded'] = false;
}
if ($conn->query($sql) === TRUE) {
$response['success'] = true;
} else {
$response['success'] = false;
$response['error'] = "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
header('Content-Type: application/json');
echo json_encode($response);
?>