Jump to content

Passing a variable from Javascript to PHP?


BellQuestWars

Recommended Posts

Okay, I have been looking into this for the last 3 hours, and cant find shit.  I have a page with a javascript game where the player moves around on a map. They have an X and Y coordinate, but I'm having a problem. The problem is I need to store that info in a database, and I'm having trouble learning AJAX.  Heres a little list of things:

 

Play loads the game. A php variable is taken from a database.

The player goes to those X and Y coordinates.

The player may move around. Once they move, the player is sent to a php page that updates the Database information.

The page is refreshed to the game again, where they may then move around some more.

 

The problem is, when the page is changed the values are lost. For some reasons cookies aren't working at all (like just not working for anything, even a completely different file.)  I heard something about using $_GET or $_POST, but I dont see how...

 

 

Link to comment
Share on other sites

btherl is correct.

I would sort out $_GET and $_POST before thinking about ajax.  If you aren't familiar with them it's time to do a tutorial on forms and php.

 

I had the same issue earlier this week.  Took me lots of heartache and suffering because I am a superNoob when it comes to javascript, but here is my question and own answer.

 

http://www.phpfreaks.com/forums/index.php?topic=331490.0

 

Kansas

Link to comment
Share on other sites

It's certainly possible, assuming your users use a modern browser such as Internet Explorer, Firefox or Chrome (or Safari for the apple people).  Javascript can call a php script, and the data will be available to the script in $_GET or $_POST, depending on how the javascript call was done.  Usually it would be in $_GET.

 

Javascript can then edit the HTML displayed to the user, depending on the results it gets from PHP.  Facebook is a good example of this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.