Hello , I would like to know how to retrieve an element in a variable of the game, like gold for example. Because I use the HTML 5 mode to develop my game browser , in order to rank I'd like to recover some value of the game. And if possible, integrated in real time in a database.
thank you in advance
Are you asking how to obtain the game's variables, so you can store them in a PHP variable - or are you also asking how to store it in the PHP variable? (Since you talk about databases and that suggests some prior knowledge, I am assuming the former?)
thank you for your reply , I know the name of the variable : $ gameParty.gold ()
I will wish her out of the game to the store on a dynamically variable PHP and Ajax I suppose; to insert it in a database. but I do not know how to start ?
You'll have to send the variable to the server, either through ajax, a post or a simple get request.
While we could just explain how to do this, I recommend you check how ajax and integrating JS with PHP works, because it'll be important for you to understand what you're doing.
Hudell thanks for this. But if i do a GET method, anyone can modify and had lots of gold into my DB with GET method on link.
I want to know how to obtain dynamic variable, to use it with a php and ajax method. I learn a little but if anyone can help me for this little thing. Thank you more.
Since the game runs in JavaScript, the only way to prevent manipulation would be to do all important calculations on the server. If it's a singleplayer game, i wouldn't bother with it, if it's a multiplayer game, you got a whole lot of other problems to overcome.
This is a single player , i have already make a script in JS, and i have 4 website use it, if nobody want to help me, to have a little code to send a variable to php by ajax inside RMMV, thank you for your help delete this question, if you want.
I know how to get a variable to my PHP page, but the variable not Refresh without refresh page. Have you a solution for this? this is my code :
switch($_GET['action']) { case 'add': $gold = $_GET['gold']; echo $gold; break; }my Browser debuging say when i launch a XMLhttpRequest this :
index.php?action=add&gold=158But its not display to php screen
Your php is running, but isn't doing anything with the variable other than echoing it.
If you check the "Network" tab of chrome's developer tools, you'll probably see the number 158 on the Response of that request. If you do, this means that the PHP executed correctly.
yes but when i do this :
$user="root";$pass="root";$bdd = new PDO('mysql:host=localhost;dbname=flym', $user, $pass);if($_GET['gold']) {$sql_insert=$bdd->query('INSERT INTO gold(gold) VALUES("'.$_GET['gold'].'")');}Nothing be appear on database ?? Why ? The request work when i type in on Php admin.
In debugging, does it work without if get gold?
var_dump($bdd);
var_dump($user);
var_dump($pass);
var_dump($sql_insert);
Paste those 4 in and tell me what it says on the page please
All are ok i think. It working on the Index.php page, but not on the call page (action.php)
source file :
<pre class='xdebug-var-dump' dir='ltr'><b>object</b>(<i>PDO</i>)[<i>1</i>]</pre><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'root'</font> <i>(length=4)</i></pre><pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'root'</font> <i>(length=4)</i></pre><pre class='xdebug-var-dump' dir='ltr'><b>object</b>(<i>PDOStatement</i>)[<i>2</i>]<i>public</i> 'queryString' <font color='#888a85'>=></font> <small>string</small> <font color='#cc0000'>'INSERT INTO gold(gold) VALUES("5")'</font> <i>(length=34)</i></pre>EDIT : OOH Sorry, Working now, the action.php dir has not on the good dir, so sorry, if you want i can post my plugin for Ajax in php ?