I am trying to do isset($_GET but I have a bizarre problem come up. I am using “id” as one of my fields but when I try to use it in the code it says it is not recognised. However I use this field quite widely.
The code its coming up with is “Undefined variable: id” but I cant see why it has a problem with id.
Same way you do with the other variables you are using AFTER the query.
$id_to_use_in_the_query = $_GET['id'];
$sql = mysql_query("
SELECT
*
FROM
productfeed
WHERE
id='". mysql_real_escape_string($id_to_use_in_the_query) ."'
LIMIT 1
");
There are a couple of other things to note.
If you use an incoming variable that the user may have some control over - you MUST always sanitise it. Thats what the mysql_real_escape_string function does. Read up on the documentation and keep your database safe!
Also, using SELECT * should be avoided. Select only the fields you need and explicitly call them.
You are using the user input in a query without sanitizing it, creating a big security hole. Spike’s solution does sanitize the user input, and thus is much better (and posted a day earlier too ).
I was using a guide on YouTube which did have a sanitiser but couldn’t get it to work.
In the video it just said that if you dont use a sanitiser it doesn’t deliver a good user experience if something goes wrong. It doesn’t discuss security.
If you dont use a sanitiser what is the security risk?