-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddreviewaction.php
94 lines (91 loc) · 2.96 KB
/
addreviewaction.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/*
session_start();
if(!isset($_SESSION['userID']))
{
include("loginform.php");
exit();
}
*/
if(isset($_POST['customerName']))
{
$error = array();
$data = array();
$uploaderror = "";
if(isset($_FILES['picture'])){
$allowed = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png');
if(in_array($_FILES['picture']['type'], $allowed)){
if(move_uploaded_file($_FILES['picture']['tmp_name'], "images/{$_FILES['picture']['name']}")){
$reviewImagePath = $_FILES['picture']['name'];
$data['customerImage'] = $reviewImagePath;
}
else {
switch($_FILES['picture']['error']){
case 1:
$uploaderror .= "This file exceeds the upload_max_filesize setting in php.ini";
break;
case 2:
$uploaderror .= "This file exceeds the MAX_FILE_SIZE setting in the HTML";
break;
case 3:
$uploaderror .= "The file was only partially uploaded.";
break;
case 4:
$uploaderror .= "No file was uploaded.";
break;
case 6:
$uploaderror .= "No temporary folder was available.";
break;
default:
$uploaderror .= "A system error occurred.";
}
}
} else {
$uploaderror .= "Please upload a PNG, JPG, or GIF.";
}
} else {
$error[] = "Please select a file to upload.";
}
if($_POST['customerName'] != "")
{
$customerName = $_POST['customerName'];
$data['customerName'] = $customerName;
}
else
{
$error[] = "You need to enter your name";
}
if($_POST['customerLocation'] != "")
{
$customerLocation = $_POST['customerLocation'];
$data['customerLocation'] = $customerLocation;
}
else
{
$error[] = "You need to enter your location (just a state is fine)";
}
if($_POST['reviewText'] != "")
{
$reviewText = $_POST['reviewText'];
$data['reviewText'] = $reviewText;
}
else
{
$error[] = "You need to enter a review";
}
if(empty($error)){
include("dbconnect.php");
$query = $dbc->prepare("INSERT INTO reviews (customerName, customerLocation, reviewText, customerImage) VALUES (:customerName, :customerLocation, :reviewText, :customerImage)");
$query->execute($data);
header("location:index.php");
}
else{
$message = "<ul>";
foreach($error as $value)
{
$message .= "<li>$value</li>";
}
$message .= "</ul>";
header("location:addreviewform.php");
}
}