I'm having trouble trying to send data between two pages. I have looked for examples but could not figure it out at all; it's frustrating.
The SQL is the following:
$query = "SELECT post_id, title , bodyofpost , username, datetime
FROM Post GROUP BY datetime DESC
LIMIT ?,?";
Here is the code snippet of the first PHP page that has the data that is needed to be sent to the other:
while ($stmt->fetch())
{
echo "Post ID: ".$post_id."<br/>";
echo "Title : ".$title."<br/>";
echo "<strong> Username: ".$username."</strong><br />";
echo "BodyofPost: ".$bodyofpost."<br/>";
echo "Date Created: ".$datetime."<br/><p>";
echo $addComment = "<a href=\"addComments.php?$post_id\">AddComment</a>";
echo"</br>";
echo"</br>";
}
This is the add comments page that the postID needs to be sent to. It has a hidden value and when I try to insert the postID into the database, the postID is always 0, which it shouldn't be.
echo'</form>';
echo '<form method="post" action="addComments.php">';
echo'<input type="hidden" name="post_id" value="postID"/>';
echo '<table>';
echo '<tr><td>Comments:</td>';
echo '<td><input type="text" name="comment"></td></tr>';
echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="PostComment"></td></tr>';
echo '</table></form>';
Ignore the comment form above; it works.
This is the part of the add comment code where I tried inserting only the postID into the database to test if it works but it didn't.
if(isset($_GET['post_id'])){
$postID= $_GET['post_id'];
$sql = "INSERT INTO Comments (post_id)
VALUES ('$postID') ";
}
So let's say we have 10 posts and we group by descending order and I clicked the linked for post 10. Then it would send me to the addcomment page and I typed in the desired comments etc. Then when I go and check the inserted comment at my database the post ID would always be 0; it should be 10 because it's the postID I was commenting on. Any help is appreciated!! Thank you!!