单击元素后显示项目详细信息

时间:2018-02-20 21:44:51

标签: php html css mysql

我正在开发一个项目,我们在数据库中有一些项目显示在网站上,下面有正常工作的代码:

<form method="post" action="store.php?action=add&ItemNo=<?php echo $products['ItemNo']; ?>">
    <a href="product.php"><div class="products">
        <img src="<?php echo $products['img'];?>" class="img-responsive"/>
        <!--  this connects to the database and gets the image of item    -->
        <h4><?php echo $products['ItemName'];?></h4>
        <h3>$ <?php echo $products['Price'];?></h3> 
        <input type="text" name="Quantity" class="form-control" value="1"/>
        <!--  This creates an box where the default qnt is set to 1    -->
        <input type="hidden" name="ItemName" value="<?php echo $products['ItemName']; ?>" />
        <input type="hidden" name="Price" value="<?php echo $products['Price']; ?>" />
        <input type="submit" name="addtocart" style="margin-top:5px;" class="btn btn-info"
               value="Add to Cart"/>
        <!--   this creates the btn that adds item to cart   -->
        </div>
    </a>
</form>

现在我正在尝试显示有关每种产品的更多详细信息。我想要的只是当用户点击他们将被发送到item.php页面的任何项目时,将会有更多关于该特定项目的详细信息。

此时我在item.php中显示了所有信息,我被卡住了。

我不知道如何说出这个问题,也许这就是我无法在Google上找到任何帮助的原因。我是PHP的新手,因为几周前我刚刚开始使用它。

1 个答案:

答案 0 :(得分:0)

首先

<a href="product.php?id=<?php echo $products['ItemNo']; ?>"> 

然后在product.php上查看$ _GET [&#39; id&#39;]的网址,并在查询中使用该网址。

SELECT * from foo where id=$id

但是除非你喜欢被黑客攻击,否则不要使用原始id或非参数化查询

相关问题