My comment was getting a bit long so I post it as an answer.
Like others said. If you send a value with the url to your script so you need to get it with $_GET
instead of $_POST
To make sure the id is really a number you could use (int)
like $productid = (int)$_GET['id'];
. The (int)
will turn your variable into a number, if its not a number it will return 0
So you could also make a checj before your query if the $productID is larger then 0 to prevent allot og zero's in your database
Also use the isset function like $productID = isset($_GET['id']) ? (int)$_GET['id'] : 0
so if some one visit your url without the parameter id he wont get an undefined error.
For your queries please use prepared statements or PDO to prevent sql injection
EDIT:
On w3schools I found some nice explaination and examples about prepared statements and PDO try to implement those examples into your own project
Second EDIT:
I was reading the example of prepared statements of the link I posted, and they make 1 small mistake in my opinion.
After the $stmt->execute()
they asume the data is inserted correcly. But to make sure the data is really inserted you schould change that part into:
// Check if there is really inserted some rows into the database or not
if ($stmt->affected_rows > 0) {
echo "New records created successfully";
}