gerit99 Posted June 11, 2012 Share Posted June 11, 2012 (edited) My idea is to create a game with PHP,Javascipt and AJAX. But I have some trouble with AJAX. I've read W3schools.com and other pages, but i couldn't figure how I could change a database each time you click a button.<---------- My character btw Edited June 11, 2012 by gerit99 1 Link to comment Share on other sites More sharing options...
Ingolme Posted June 11, 2012 Share Posted June 11, 2012 Do you know how to change the database with PHP? All you need to do is load a PHP file that changes the database using AJAX. Link to comment Share on other sites More sharing options...
gerit99 Posted June 12, 2012 Author Share Posted June 12, 2012 Really? Wow... I'll take a look on how to use it. Link to comment Share on other sites More sharing options...
gerit99 Posted June 12, 2012 Author Share Posted June 12, 2012 (edited) I've made a script but it doesn't work. I've tried alot of things but it doesn't work, and since I'm at school i can't show my script. I've used _GET to read the info, and then i updated it. Edited June 12, 2012 by gerit99 Link to comment Share on other sites More sharing options...
birbal Posted June 12, 2012 Share Posted June 12, 2012 we need to see the codes and error if any is there, to help you Link to comment Share on other sites More sharing options...
gerit99 Posted June 12, 2012 Author Share Posted June 12, 2012 (edited) The problem is, there are no errors. Each keypress triggers this: var serverRequest=new XMLHttpRequest();function updatePlayerPosition(){serverRequest.open("GET","updatePositions.php?player=1&posTop="+document.getElementById('player').style.posTop+"&posLeft="+document.getElementById('player').style.posTop,true);serverRequest.send();} updatePositions.php <?PHP$player = $_GET["player"];$posTop = $_GET["posTop"];$posLeft = $_GET["posLeft"];mysql_query("UPDATE userplayers SET posTop=".$posTop.",posLeft=".$posLeft." WHERE playerID=".$player."");?> And still I see this: posTop | posLeft 300 | 300 Edited June 12, 2012 by gerit99 Link to comment Share on other sites More sharing options...
boen_robot Posted June 12, 2012 Share Posted June 12, 2012 You're missing out really important pieces in the code you're presenting, but even from the little you're giving, it's clear that you're not setting the posTop and posLeft URL variables correctly.You have serverRequest.open("GET","updatePositions.php?player=1&posTop="+document.getElementById('player').style.posTop+"&posLeft="+document.getElementById('player').style.posTop,true); but there's no "posTop" property on the "style" object. The "style" object reflects the inline style (as you write them with the "style" attribute). From it, you have the "top" and "left" properties instead, i.e. serverRequest.open("GET","updatePositions.php?player=1&posTop="+document.getElementById('player').style.top+"&posLeft="+document.getElementById('player').style.left,true); Link to comment Share on other sites More sharing options...
gerit99 Posted June 12, 2012 Author Share Posted June 12, 2012 posTop works too, somehow. That's how i have been scripting it. I also need to paste the important pieces in my script Link to comment Share on other sites More sharing options...
thescientist Posted June 14, 2012 Share Posted June 14, 2012 posTop works too, somehow. That's how i have been scripting it. I also need to paste the important pieces in my script then as mentioned, please show ALL relevant code. what I don't get, is after the AJAX request get's made, what is supposed to happen? I don't see any callbacks being implemented, and nothing in the PHP code past the query. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now