正如你所看到的,我有這個頁面,每個表格行上都有'add to cart'按鈕。比方說,我點擊「添加到購物車」的產品ID爲1的錶行,我想要productid,productname,cartquantity轉移到另一個網頁上的購物車。可能嗎?提交表格的每一行,將該行的數據插入到數據庫
好了,所以你可以看到我想產品ID 1添加到我的車與量3.但是,當我按下添加到購物車
它總是跑到我的最後的productid是shofffwef並將其添加到購物車中。不知道是怎麼回事錯:(
下面是添加到購物車按鈕
if(isset($_POST['insert'])){ //$_POST[X] X = name of textbox (***You got to do this In BASHOP) take note the productname.
$queryinsert = "insert into cart(productid,productname,cartquantity,amount) SELECT productid,productname,'$_POST[cartquantity]', '50' FROM product WHERE productid='$_POST[hidden]'";
mysqli_query($dbconn,$queryinsert);
}
這裏是我的代碼,以顯示該表中的第一張照片。
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>"."<input type = 'text' name='productid' value=". $row['productid'] ."></td>";
echo "<td>"."<input type = 'text' name='productname' value=". $row['productname'] ."></td>";
echo "<td>" . $row['retailprice'] . "</td>";
echo "<td>" . $row['pointsformula'] . "</td>";
echo "<td>"."<button type='button' class='quantityaddsub' id='sub' onclick='quantitysub(".$row['productid'].")'>-</button>".
"<input type='text' class='quantity' name='cartquantity' id='quantity".$row['productid']."' value=1>".
"<button type='button' class='quantityaddsub' id='add' onclick='quantityadd(".$row['productid'].")'>+</button>".
"<input type='hidden' name='hidden' value=".$row['productid']."></td>";
echo "<td>" . "<input type='submit' name='insert' value='Add To Cart'" . "></td>";
echo "</tr>";
}
echo "</table>";
我的SQL代碼
我到處搜索,但沒有找到解決辦法,請幫助我謝謝!
我覺得你需要'
'標籤爲每一行。 – frz3993@ frz3993 yup,我做到了,但並沒有在這裏顯示,同時添加方法='發佈'
標記 – Marcus@Marcus在我的答案 – gibberish