How do I check in php to see if a URL variable is present?

I want to check to see if a URL variable is present or not.

This doesn't work. I thought <> '' would be enough to check if 'x' variable is present or not. it is giving me an UNEXPECTED T-VARIABLE error. I think there should be a step earlier checking to see if X variable is there at all before checking its value, correct? (on some of my links, x variable is not present and on some it is.

if $_GET['x'] <> '';
$x_coordinate = $_GET['x'];
else $x_coordinate = 0.0;
<?php
$name = $_GET['name']."/thumbs/"; //"'".$_GET['name']."/thumbs/'";   //stores the URL variable into a variable that php can use
$filedir = $_GET['file'];
$nameonly = $_GET['name'];
 
if $_GET['x'] <> '';
$x_coordinate = $_GET['x'];
else $x_coordinate = 0.0;
if $_GET['y'] <> '';
$y_coordinate = $_GET['y'];
else $y_coordinate = 0.0;
if 
$zoom = $_GET['zm'] <> '';
else $zoom = 25;
//echo $name , $file
?>

Open in new window

polaatxAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
Try:

<?php
$name = $_GET['name']."/thumbs/"; //"'".$_GET['name']."/thumbs/'";   //stores the URL variable into a variable that php can use
$filedir = $_GET['file'];
$nameonly = $_GET['name'];
 
if (isset($_GET['x']) && $_GET['x'] != '')
{
	$x_coordinate = $_GET['x'];
}
else
{
	$x_coordinate = 0.0;
}
 
if( isset($_GET['y']) && $_GET['y'] != '')
{
	$y_coordinate = $_GET['y'];
}
else
{
	$y_coordinate = 0.0;
}
 
if (isset($_GET['zm']) && $_GET['zm'] != '')
{
	$zoom = $_GET['zm']
}
else
{
	$zoom = 25;
}
//echo $name , $file
?>

Open in new window

0
 
ee_rleeCommented:
hi

 i think you missed the if statement for this.

if
$zoom = $_GET['zm'] <> '';
else $zoom = 25;

0
 
polaatxAuthor Commented:
Hi hielo: did you write all the  {  signs  by hand and position them so neatly or is there a program that does this for you?
0
 
hieloCommented:
By hand. It's fun :)
Rumor has it that there are programs out there, but I wouldn't know which ones they are.
0
 
polaatxAuthor Commented:
thank you. More than what I expected.
0
All Courses

From novice to tech pro — start learning today.