-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmemepost.php
More file actions
57 lines (53 loc) · 2.14 KB
/
Copy pathmemepost.php
File metadata and controls
57 lines (53 loc) · 2.14 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
<?php
include('./partials/header.php');
include_once('./includes/db.inc.php');
if (isset($_POST['submit'])) {
echo '<pre>';
var_dump($_POST);
var_dump($_SESSION);
echo '</pre>';
$username = $_SESSION['username'];
$imageurl = $_POST['imageUrl'];
$caption = $_POST['memeCaption'];
$sql = 'INSERT INTO memes (username, url, caption) VALUES (?,?,?);';
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die('stmt could not be prepared');
}
mysqli_stmt_bind_param($stmt, "sss", $username, $imageurl, $caption);
mysqli_stmt_execute($stmt);
}
$sql = 'SELECT * FROM memes ORDER BY id DESC;';
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
die('stmt could not be prepared');
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
?>
<div class="container">
<form action="" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="formFile" class="form-label">Upload your meme here. The submit button will only show up once an image is uploaded!</label>
<input class="form-control" type="file" name="image" id="file-upload">
<input class="hidden" type="text" value="bruh" name="imageUrl" id="imageUrlInput">
</div>
<div class="mb-3">
<label for="formFile" class="form-label">Enter a caption for your post</label>
<input class="" type="text" value="" name="memeCaption" id="memeCaption" placeholder="Caption..">
</div>
<button class="btn btn-secondary hidden" type="submit" name="submit" id="submitbtn">Upload</button>
</form>
<h1>Recent Posts: </h1>
<?php while($resultArray = mysqli_fetch_assoc($result)) { ?>
<div class="card w-25" style="margin: 17px auto;color: black;">
<img class="card-img-top" src="<?php echo $resultArray['url']?>" alt="Card image">
<div class="card-body">
<h4 class="card-title">Posted by: <?php echo $resultArray['username'] ?></h4>
<p class="card-text"><?php echo $resultArray['caption'] ?></p>
<a href="post.php?id=<?php echo $resultArray['id'] ?>">View Post</a>
</div>
</div>
<?php } ?>
</div>
<?php include('./partials/footer.php'); ?>