I’m creating a website that relies on $_GET to function correctly.
It works like this: http://www.example.com/show?q=14&i=48 q and i are IDs on MySQL server that must be fetched using mysql_query() and the like. Parameters are always integers.
If someones type the url without any parameters both PHP and MySQL yells errors. PHP for undefined variable(s) and MySQL for incorrect syntax.
What i’ve tried so far doesn’t works i always get “Error”;
if (is_int($_GET['q']) AND is_int($_GET['i']))
{
echo "All good.";
}
else
{
echo "Error.";
}
What am i doing wrong here.
Thanks,
atno
That’s because you’re checking the type of the variable and not its content. Anything coming from a query string via
$_GETis considered a string, so you should usectype_digit()instead ifis_int(), and also checking if the values are present withempty().