-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddposts.php
132 lines (109 loc) · 2.73 KB
/
addposts.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
// Create database connection
$db = mysqli_connect("localhost", "Kyle12_12", "MaddenBase12", "maddenbaseposts");
// Initialize message variable
$msg = "";
// If upload button is clicked ...
if (isset($_POST['upload'])) {
// Get image name
$image = $_FILES['image']['name'];
// Get text
$positionteam = mysqli_real_escape_string($db, $_POST['positionteam']);
$description = mysqli_real_escape_string($db, $_POST['description']);
// image file directory
$target = "./images/".basename($image);
$sql = "INSERT INTO posts (image, positionteam, description) VALUES ('$image', '$positionteam', '$description')";
// execute query
mysqli_query($db, $sql);
if (move_uploaded_file($_FILES['image']['tmp_name'], $target )) {
$msg = "Post added successfully";
}else{
$msg = "Failed to add your post";
}
}
$result = mysqli_query($db, "SELECT * FROM posts");
?>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
<style type="text/css">
#content{
width: 80%;
margin: 20px auto;
border: 1px solid #cbcbcb;
}
form{
width: 50%;
margin: 20px auto;
}
form div{
margin-top: 5px;
}
#img_div{
width: 80%;
padding: 10px;
margin: 15px auto;
border: 1px solid #cbcbcb;
}
#innerdiv {
height: 140px;
padding: 0px;
display: flex;
align-content: center;
align-items: center;
justify-content: center
}
#img_div:after{
content: "";
display: block;
clear: both;
}
img{
display: flex;
float: inline start;
float: left;
margin: 0px;
width: 300px;
height: 140px;
}
.inline {
display:inline-block;
width: 20%;
margin: 20px;
}
.inline1 {
}
</style>
</head>
<body>
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img src='images/".$row['image']."' >";
echo "<div id = 'innerdiv'>";
echo "<span class='inline'>".$row['positionteam']."</span>";
echo "<span class='inline'>".$row['description']."</span>";
echo "</div>";
echo "</div>";
}
?>
<form method="POST" action="addposts.php" enctype="multipart/form-data">
<input type="hidden" name="size" value="1000000">
<div>
<input type="file" name="image" width="100%">
</div>
<div>
<input type="text" name="positionteam">
</div>
<div>
<textarea name="description" cols="40" rows="5"></textarea>
</div>
<div>
<button type="submit" name="upload" >POST</button>
</div>
</form>
</div>
</body>
</html>