Nour
Nour

Reputation: 11

unable to get id from URL php

I want to get the id when pressing a button in order to delete an item from a session. The id appears in the URL but i'm not able to get it using $_GET.

<form action="Shop.php?id= <?php echo $values["ProductCode"]; ?>" method= "post">
<input type= "submit" name="remove" value= "Remove" class= "btn btn-danger">

</form>

if(isset($_POST['remove'])){

foreach($_SESSION["shopping_cart"] as $keys => $values){
if($values["ProductCode"] == $_GET['id']){

unset($_SESSION["shopping_cart"][$keys]);
echo '<script>alert("Item Removed")</script>';
echo '<script>window.location="Shop.php"</script>';

Upvotes: 0

Views: 377

Answers (1)

RiggsFolly
RiggsFolly

Reputation: 94642

Remove the space between id= and <?php echo $values["ProductCode"];?>

<form action='Shop.php?id=<?php echo $values["ProductCode"];?>' method='post'>

Upvotes: 1

Related Questions