-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddpaint.php
More file actions
111 lines (88 loc) · 3.34 KB
/
addpaint.php
File metadata and controls
111 lines (88 loc) · 3.34 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
//!
//! This webpage uses a form in order to add title, year, height, width and img to Paint.paints in MySql
//! Note: The img column only holds the path to image not the image it self. The image needs to be added
//! separately. If there is no image in the designated path, it will still be displayed as a list item
//! on the home page, scuddha.php. without the image (until it is deleted using PhpMyAdmin).
//!
//! Currently there is no link to this file from other pages. It can be accessed at
//! http://localhost:8888/addpaint.php
//!
try{
//! if statement checks to see if form has input
if ($_POST) {
$title = $_POST['title'];
$year = $_POST['year'];
$height = $_POST['height'];
$width = $_POST['width'];
$imgpath = $_POST['imgpath'];
//! checks to make sure all form fields are fill out
if ($title == "" || $year == "" || $height == "" || $width == "" || $imgpath == ""){
include("inc/header.php");
echo "<h1>Whoops!! You need to fill out ALL the info!</h1>";
include("inc/footer.php");
exit;
}
//! protects against auto form fillers
if ($_POST["address"] != "") {
echo "Bad form input";
exit;
}
//! get connection to DATABASE Paint TABLE paints
include("inc/connection.php");
//! prepares INSERT statement for MySql
$statement = $db->prepare("INSERT INTO `paint`.`paints` (`title`, `year`, `height`, `width`, `img`)
VALUES (:title, :year, :height, :width, :imgpath)");
$statement->bindParam(':title', $title);
$statement->bindParam(':year', $year);
$statement->bindParam(':height', $height);
$statement->bindParam(':width', $width);
$statement->bindParam(':imgpath', $imgpath);
//! executes INSERT statement
$statement->execute();
//header("location:addpaint.php?status=uploaded");
}
} catch (Exception $e) {
echo "Unable to add new row";
exit;
}
include("inc/header.php");
//! Still working on the status to change. Not being right used right now
if (isset($_GET["status"]) && $_GET["status"] == "uploaded"){
echo "<h3>Stats uploaded successfully</h3>";
} else { ?>
<div class="">
<form method="post" action="addpaint.php">
<div class="form-group">
<table>
<tr>
<th><label for="title">Name</label></th>
<td><input type="text" id="title" name="title" class="form-control" /></td>
</tr>
<tr>
<th><label for="year">Year</label></th>
<td><input type="text" id="year" name="year" class="form-control"/></td>
</tr>
<tr>
<th><label for="height">Height</label></th>
<td><input type="text" id="height" name="height" class="form-control"/></td>
</tr>
<tr>
<th><label for="width">Width</label></th>
<td><input type="text" id="width" name="width" class="form-control"/></td>
</tr>
<tr>
<th><label for="imgpath">Img path</label></th>
<td><input type="text" id="imgpath" name="imgpath" class="form-control"/></td>
</tr>
<tr style="display:none">
<th><label for="address">Address</label></th>
<td><input type="text" id="address" name="address" />
<p>please leave this field blank</p></td>
</tr>
</table>
<input type="submit" value="add new" class="btn btn-secondary"/>
</form>
</div>
<?php } ?>
<?php include("inc/footer.php"); ?>