Page 1 of 1

How to add and subtract to integer using variable?

Posted: Sun Feb 13, 2011 5:53 pm
by struct
Hi,

I'm trying to do some simple math with user input but I can't seem to get it to work right.

Code: Select all

$orglong=htmlspecialchars($_GET[long]);
echo $orglong." ".$orglat;

$minlong=$orglong-500;
$maxlong=$orglong+500
echo $minlong." ".$maxlong;
I confirmed the browser excepts the values and returns the echo statement on $orglong
but when I applied the $minlong and maxlong values, this is the error i get.
Parse error: syntax error, unexpected T_ECHO in /xxxxxxxxx/xml_math.php on line 11

I would appreciate if you can give me some pointers or direct me to right place for me to research this topic.

Re: How to add and subtract to integer using variable?

Posted: Sun Feb 13, 2011 6:00 pm
by struct
nevermind. I didn't put ; on one of the statements.

Re: How to add and subtract to integer using variable?

Posted: Sun Feb 13, 2011 6:01 pm
by McInfo
Unless long is a constant, identify it as a string by wrapping it in quotes.

Code: Select all

$_GET['long']

Re: How to add and subtract to integer using variable?

Posted: Sun Feb 13, 2011 6:19 pm
by struct
Thanks McInfo.
Its a constant. I'm trying to calculate the longitude & Latitude.

Re: How to add and subtract to integer using variable?

Posted: Sun Feb 13, 2011 6:30 pm
by Jonah Bron
Are you sure? Do you know he means this kind of constant?

http://php.net/constants