我對 $_GET 有疑問。在我的 index.php 文件中,我有一個小購物網(wǎng)站,我可以通過單擊“購買”按鈕購買隨機物品。單擊“購買”按鈕后,我試圖獲取點擊產(chǎn)品的 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"; }我總是收到錯誤消息..
1 回答

慕斯王
TA貢獻1864條經(jīng)驗 獲得超2個贊
在這里addtocart.php?id你已經(jīng)使用過id,所以在 URL 中它將傳遞參數(shù)為id
$response .= "<a href='addtocart.php?id=". $row['ProduktID'] . "'><button class='inCart'>Buy</button></a>";
添加到購物車.php:
所以在php中你應該訪問$_GET['id']
<?php
session_start();
if(isset($_GET['id']) && !empty($_GET['id'])){
//Do Stuff
}
else{
echo "Error, can't add the item";
}
- 1 回答
- 0 關注
- 149 瀏覽
添加回答
舉報
0/150
提交
取消