Skip to content

Commit

Permalink
upgrade: post in anonymous
Browse files Browse the repository at this point in the history
  • Loading branch information
didof committed Jan 17, 2020
1 parent 5433c3c commit 8412a8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 7 additions & 6 deletions includes/deletePost.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
include_once "dbh.inc.php";

# Aggiungi goaway
# vedi se c'è l'immagine, evenutalmente devi cancellarla
# cancella dal database il post richesto

$post = $_GET["idPost"];
echo 'idPost => ' . $post . '<br>';

$sql = "SELECT * FROM post WHERE id=?";
$sql = "SELECT * FROM post WHERE post_id=?";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "i", $post);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$image = mysqli_fetch_assoc($result);
echo '$image => ';
print_r($image);

$dir = $image["post_dir"];
$author = $image["post_author"];
$fileName = $image["post_file_name"];
echo $fileName;

if ($fileName == "") {
# Cancel from database
$sql = "DELETE FROM post WHERE id=?";
$sql = "DELETE FROM post WHERE post_id=?";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "i", $post);
Expand All @@ -36,7 +37,7 @@
echo '>Error: file was not deleted.';
} else {
# Cancel from database too
$sql = "DELETE FROM post WHERE id=?";
$sql = "DELETE FROM post WHERE post_id=?";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "i", $post);
Expand Down
12 changes: 9 additions & 3 deletions includes/showPost.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@
if (mysqli_num_rows($query) > 0) {
while ($row = mysqli_fetch_assoc($query)) {
echo '<div class="post">
<div class="header">
<div><img src="uploads/' . $row["name"] . '" height="40px" width="40px"></div>
<div class="header">';
if ($row["post_dir"] == "anonymous") {
echo '<div><img src="uploads/anon_profile_img.png" height="40px" width="40px"></div>
<div>' . $row["post_title"] . '</div>
<div>Anonymous</div>';
} else {
echo '<div><img src="uploads/' . $row["name"] . '" height="40px" width="40px"></div>
<div>' . $row["post_title"] . '</div>
<div>' . $row["post_author"] . ' (' . $row["post_user_id"] . ')</div>';
}
if ($userId == $row["post_user_id"]) {
echo '<div><button>Comment</button></div>
<div><button>Modify</button></div>
<div><a href="includes/deletePost.inc.php?idPost=' . $row["id"] . '"><button>Cancel</button></a></div>';
<div><a href="includes/deletePost.inc.php?idPost=' . $row["post_id"] . '"><button>Cancel</button></a></div>';
} else {
echo '<div></div>
<div></div>';
Expand Down

0 comments on commit 8412a8d

Please sign in to comment.