Page 1 of 1

Queries in a location-script

Posted: Wed Aug 10, 2005 2:26 am
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??

Posted: Wed Aug 10, 2005 7:42 am
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.