Jump to content

Form Submit


Recreational_Champ

Recommended Posts

Hello all~  I have made a php game printing out images using a multidimensional array stored within a session variable named 'board.'  I am having quite some time trying to navigate the current state of my player. 

 

<form action="this.php" method="get" accept-charset="utf-8">
<input type="submit" name="right" value="→">
<input type="submit" name="left" value="←">
<input type="submit" name="up" value="↑">
<input type="submit" name="down" value="↓">
<input type="submit" name="reset" value="reset;">
</form>

 

 

if(isset($_GET['right']))
{
$dir = "right";
move($dir);
}
if(isset($_GET['left']))
{
$dir = "left";
move($dir);
}
if(isset($_GET['up']))
{
$dir = "up";
move($dir);
}
if(isset($_GET['down']))
{
$dir = "down";
echo "$dir";
}
if(isset($_GET['reset']))
{
session_destroy();
   setcookie(session_name(),"", time() - 3600);
   $_SESSION=array();
echo "reset";

 

 

Now, I can move the player in any direction I choose, but I have to hit the submit button "twice" to get the player to move only after I have moved in a different direction. 

 

Example:

 

New session started, player in a random position...

 

Try to navigate player up/down/left/right and it will move in the direction I last clicked "once" before moving the current selection... even when cookies/sessions have been cleared.

 

Somehow the submit GET status retains last moved state;  I am one click behind and cannot figure it out

 

 

My move() is working just fine!  Problem occurs when I submit reset as well.

 

 

A walk through would be very helpful :)

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/131115-form-submit/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.