Sending a PHP variable to another page via click on anchor tag

mysql, php, post

Solution

Product List.php

<a href="product-detail.php?product_id=1">Product</a>

On product-detail.php

$product_id = (int)$_GET['product_id'];

Then, bind $product_id to your DB query.

You can easily replace this with a urlencoded product name, but you really should stick with unique identifiers for this.

foreach ($products as $product) {
    echo '<a href="product-detail.php?id=' . $product['id'] . '">' . $product['name'] . '</a>';
}

Problem

This is a simplified version of the files that I am working with: On product-list.php I have something like: ``` <ul> <li><a href="prouduct-detail.php">Product1</a></li> <li><a href="prouduct-detail.php">Product2</a></li> <li><a href="prouduct-detail.php">Product3</a></li> </ul> ``` on product-detail.php I want to use something like: ``` include_once("db_config.php"); $product_detail_query = 'SELECT * FROM prod_details WHERE product_name = ???'; ``` When someone clicks on a product in product-list.php I want the text between the anchor tags to get sent to product-detail.php and beplaced in the SQL query at product_name = (where I have ???) so I can access that specific row and lay out the details. What is the best way to achieve this?

Original source