简体   繁体   中英

How can I redirect to a PHP page with an <a> tag? Also how can I pass an ID number through the URL with it?

For my PHP project I am using a post method for the form and I want to be able to redirect to a PHP page with an <a> tag.

This is the code that I want to use to redirect, but I don't know how to make it work with the <a> tag.

$query_string = ['item' => $_SESSION['items']];
$url_query = http_build_query($query_string);
header("location:detailPage.php?$url_query");

Also, How can I pass an ID number through the URL from the current page to a different PHP page?

You can use html tag with embedded php code

<a href="detailPage.php?id=<?php echo $url_query; ?>">TEXT</a>

in detailPage.php you will call it like

if(isset($_GET['id'])//getting id from url using $_GET request
{
   $id = $_GET['id'];//storing in php variable
}

I hope this will help you. If there is anything wrong kindly let me know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM