简体   繁体   中英

Passing retrieved value from database into another page

how can i retrieve specific product details from this page to another page when i click the link?

This is my code for displaying all products in database:

<div class="features_items"><!--features_items-->
<h2 class="title text-center">Features Items</h2>
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tblforface ORDER BY prodid ASC");
if (!empty($product_array)) { 
    foreach($product_array as $key=>$value){
?>
<div class="col-sm-4">
    <div class="product-image-wrapper">
        <div class="single-products">
            <div class="productinfo text-center">

                <img src="images/shop/product12.jpg" alt="" />
                <h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
                <p><?php echo $product_array[$key]["prodname"]; ?></p>
                <a href="../homescreen/product/product.php" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
            </div>
            <div class="product-overlay">
                <div class="overlay-content">
                    <h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
                    <p><?php echo $product_array[$key]["prodname"]; ?></p>
                    <a href="../homescreen/product/product.php" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
                </div>

            </div>
        </div>
        <div class="choose">
            <ul class="nav nav-pills nav-justified">
                <li><a href=""><i class="fa fa-plus-square"></i>Add to wishlist</a></li>
                <li><a href=""><i class="fa fa-plus-square"></i>Add to compare</a></li>
            </ul>
        </div>
    </div>
</div>

You can add the id into a query string, like http://blah.com/product.php?id=123

<a href="../homescreen/product/product.php?id=<?= $product_array[$key]["id"]; ?>" class="btn btn-default add-to-cart">
    <i class="fa fa-shopping-cart"></i>Add to cart
</a>

And in your other page,

$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

We do that instead of the dangerous $id = $_GET['id']; . Check the docs for filter_input here http://php.net/manual/en/function.filter-input.php

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