Queries in a location-script

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
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Queries in a location-script

Post by Terriator »

Hey again..I'm experiencing some troubles with this code that's supposed to update the users location in the db when one of the 4 north, east, west, south submit buttons is pressed:

Code: Select all

//North
if(isset($_POST['North'])!==false&&$user[Latitude]>2){
  doquery("UPDATE `users` SET `Latitude` = Latitude -1 WHERE `userID` ={$_SESSION['userID']} LIMIT 1 ");
  echo"<center>You moved 1 field north and was not attacked</center>";
}
//South
if(isset($_POST['South'])!==false&&$user[Latitude]<16){
  doquery("UPDATE `users` SET `Latitude` = Latitude +1 WHERE `userID` ={$_SESSION['userID']} LIMIT 1 ");
  echo"<center>You moved 1 field south and was not attacked</center>";
}
//East
if(isset($_POST['East'])!==false&&$user[Longitude]<16){
  doquery("UPDATE `users` SET `Longitude` = Longitude +1 WHERE `userID` ={$_SESSION['userID']} LIMIT 1 ");
  echo"<center>You moved 1 field east and was not attacked</center>";
}
//West
if(isset($_POST['West'])!==false&&$user[Longitude]>2){
  doquery("UPDATE `users` SET `Longitude` = Longitude -1 WHERE `userID` ={$_SESSION['userID']} LIMIT 1 ");
  echo"<center>You moved 1 field west and was not attacked</center>";
}
The problem is that if I press south twice, and then press the east button; Theninstead of instantly doing the East query it once again does the south query. What did I miss??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not entirely sure, but it may have to do with your constraints on the location.

As an aside, the following is a bad practice: $user[Latitude], instead use $user['Latitude']. The reason why: Latitude will be mistaken for a constant, when not found, PHP will fire a notice (whether you display them or not) thus slowing down the execution of your application and technically adding a bug. It may not be much of an issue now, but if you get into doing code releases to the public, some will require the code not produce a single error, warning or notice.
Post Reply