Home > database >  How to transfer information to other page with PHP?
How to transfer information to other page with PHP?

Time:01-10

How can I transfer information from one page to another with php in html css pages? Actually, I have a blog site and when one of its posts is clicked, the information of that post, such as the title, text, etc., will be displayed on a new page. My problem is how to find the ID when clicking on the post, so that I can write the query I want based on that ID

I tried this problem with the form tag so that when the user clicks on the title of the post, the page of that post opens. The title of the post is with the H2 tag, but I don't know how to transfer the ID of that post to another page

CodePudding user response:

let say you have page with all posts with titles. posts.php

<a href="postDetails.php?id=<?php echo $post_id; ?>"> <?php echo $post_title?> </a>

postDetails.php

<?php $post_id = $_GET['id'];
// do query using $post_id
?>    

CodePudding user response:

I was writing this in posts.php:

<a href="postDetails.php?id=<?php echo $post_id = "2"; ?>" target="_blank" ></a>

and this in postDetails.php:

<?php

include "Connection.php";

$post_id = $_GET['id'];

$sql = "SELECT Id FROM `projects` WHERE Title = $post_id";
$result = $con->query($sql);

if (mysqli_query($con, $sql)) {
while ($row = $result->fetch_assoc()) {
    header("Location: Project.php?id=$row[Id]");
    exit();
}
}

mysqli_close($con);

?>

But didn't worked

  • Related