购物车 $_GET 问题无法与 id 一起使用

我对 $_GET 有疑问。


在我的 index.php 文件中,我有一个小购物网站,我可以通过单击“购买”按钮购买随机物品。单击“购买”按钮后,我试图获取点击产品的 ID,如下所示:


//Stuff like connection, sql, etc..


$response="";


    while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){

        //Other Stuff...

        $response .= "<a href='addtocart.php?id=". $row['ProduktID'] . "'><button class='inCart'>Buy</button></a>";

    }

然后我有一个名为 addtocart.php 的新文件。我可以看到身份证:

图片

图片

添加到购物车.php:

<?php

  session_start();


  if(isset($_GET['ProduktID']) && !empty($_GET['ProduktID'])){

     //Do Stuff

  }

  else{

     echo "Error, can't add the item";

  }

我总是收到错误消息..


潇湘沐
浏览 134回答 1
1回答

慕斯王

在这里addtocart.php?id你已经使用过id,所以在 URL 中它将传递参数为id&nbsp; &nbsp; &nbsp;$response .= "<a href='addtocart.php?id=". $row['ProduktID'] . "'><button class='inCart'>Buy</button></a>";添加到购物车.php:所以在php中你应该访问$_GET['id']<?php&nbsp; session_start();&nbsp; if(isset($_GET['id']) && !empty($_GET['id'])){&nbsp; &nbsp; &nbsp;//Do Stuff&nbsp; }&nbsp; else{&nbsp; &nbsp; &nbsp;echo "Error, can't add the item";&nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP