EDIT: Solved the issue. In the php code $q and $q2 did not get query.
$r1 = $db->query($q);
$r2 = $db->query($q2);
I'm trying to make a micro blog new feed for a class that I'm in and I am having difficulty sending information from a post to update the like and dislike buttons. Below is the code for the post;
<form action="Assignment4_Main.php" method="post">
<div class="newsFeed">
<input type="hidden" name="submitted" value="1"/>
<a href="Assignment4_Profile.php"><?php echo $username?>
</a>
<input class="idr" name="postID" type="text" value=<?php echo $postID ?> />
<p>
<?php echo $text?>
</p>
<p>
Posted: <?php echo $pTime?>
</p>
<input type="image" name="liked" src="Like_Not.png" alt="submit" width="20" height="20" value="1"/>
<p>
Likes: <?php echo $likes?>
</p>
<input type="image" name="disliked" src="Dislike_Not.png" alt="Dislike" width="20" height="20" value="1"/>
<p>
Dislikes: <?php echo $dislikes?>
</p>
<input type="image" name="reposted" src="Repost_Not.png" alt="Repost" width="20" height="20" value="1"/>
</br>
</div>
</form>
Also here is the php code;
<?php
if(isset($_POST["postID"])){
$idPost = ($_POST["postID"]);
$db = new mysqli("host", "username", "password", "username");
if ($db->connect_error) {
die ("Connection failed: " . $db->connect_error);
}
$gettingUser = "SELECT * FROM Post WHERE post_id = '$idPost';";
$r = $db->query($gettingUser);
$row = $r->fetch_assoc();
$gotID = $row["user_id"];
$r = $db->query($gettingUser);
$row = $r->fetch_assoc();
$gotLikes = $row["likes"];
$gotLikes++;
$q = "insert into Likes (user_that_like_id, post_id) values ('$gotID', '$idPost');";
$q2 = "update Post set likes='$gotLikes' where post_id='$idPost';";
header("Location: Assignment4_Main.php");
$db->close();
exit();
}
?>
As of now I think the issue is there is nothing being sent in the POST
variable because if I put an echo after the first if nothing appears to happen. Where I'm trying to send postID so that I can update the likes and dislikes on the server.