Reputation: 3
I have a problem with $_GET.
On my index.php file I have a little shopping site where I can buy random stuff by clicking the "buy" button. After clicking the "buy" button I am trying to get the id of the clicked product like this:
//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>";
}
And then I have a new file called addtocart.php. I can see the id's:
addtocart.php:
<?php
session_start();
if(isset($_GET['ProduktID']) && !empty($_GET['ProduktID'])){
//Do Stuff
}
else{
echo "Error, can't add the item";
}
I am always getting the Error message..
Upvotes: 0
Views: 85
Reputation: 5322
Here addtocart.php?id
you have used id
, so in URL it will passed param as id
$response .= "<a href='addtocart.php?id=". $row['ProduktID'] . "'><button class='inCart'>Buy</button></a>";
addtocart.php:
so in php you should access as $_GET['id']
<?php
session_start();
if(isset($_GET['id']) && !empty($_GET['id'])){
//Do Stuff
}
else{
echo "Error, can't add the item";
}
Upvotes: 1