Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP $_GET Variable check [closed]

Tags:

php

get

I have some code that checks for a value of say, var in the link.

Http://www.blah.com/index.php?var=

But when a link like that is sent to the server it returns a database error since var isn't set. I have tried isset (which it is set so that wont stop it) but !empty doesn't stop the var from being sent to the DB.

This is the code

if(isset($_GET['id']) && !empty($_GET['id'])){
$id = mysql_prep($_GET['id']);
....
}

Any help?

like image 548
Cow Avatar asked Feb 19 '23 03:02

Cow


1 Answers

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if($id){
$id = mysql_prep($id);
....
}
like image 196
Mihai Iorga Avatar answered Feb 27 '23 15:02

Mihai Iorga