then I get errors saying that there’s an undefined index: category and undefined index: id
As I understand it the script tries to assign values to these variables that simply are not there 'cause they haven’t been sent to the script.
How can I prevent this from happening?
You actually don’t need that on most servers, you could just use $id if global variables are enabled (i think global variables is what it’s called at least)
Global variables are bad for your health. Turn them off right now! They can easily lead to security holes in your code. If you - for instance - have code like this
if (input_is_okay()) {
$valid_input = 1 ;
}
if ($valid_input) {
show_financial_data();
}
else {
show_order_form();
}
Then if the script is called like this script.php?valid_input=1 then the code will execute the show_financial_data routine even though input is not OK.
The code is much more secure from this kind of exploit if you have to access variables through the $_GET and $_POST arrays.