How to add and subtract to integer using variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
struct
Forum Newbie
Posts: 3
Joined: Sun Feb 13, 2011 5:45 pm

How to add and subtract to integer using variable?

Post 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.
struct
Forum Newbie
Posts: 3
Joined: Sun Feb 13, 2011 5:45 pm

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

Post by struct »

nevermind. I didn't put ; on one of the statements.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post by McInfo »

Unless long is a constant, identify it as a string by wrapping it in quotes.

Code: Select all

$_GET['long']
struct
Forum Newbie
Posts: 3
Joined: Sun Feb 13, 2011 5:45 pm

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

Post by struct »

Thanks McInfo.
Its a constant. I'm trying to calculate the longitude & Latitude.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post by Jonah Bron »

Are you sure? Do you know he means this kind of constant?

http://php.net/constants
Post Reply