The $_GET variable will be populated only if your URL has a query string (that usually means a form was submitted with the GET method).
So you must first check if $_GET
contains values, then use theses values:
if(isset($_GET['post']) && isset($_GET['page'))
{
$post = mysqli_real_escape_string($_GET['post']);
$page = intval($_GET['page']);
}
Casting to string
is useless in your first line of code: mysqli_real_escape_string
returns a string anyway.
In your second line of code:
- using
mysql_real_escape_string
since you are using intval
: an integer value does not need any extra escaping
- casting to
int
is useless, this was already done with intval
Important notice:
Since all mysql_* functions are deprecated and will be removed in a future version of PHP, you should use MySQLi or PDO (I used MySQLi in my code sample).