Re: exchange data from javascript to php
| From: | Marek Kilimajer | Date: | Thu, 24 Oct 2002 10:59:52 +0000 |
| Subject: | Re: exchange data from javascript to php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-121228@lists.php.net to get a copy of this message | ||
Javascript is executed on client side, PHP on server side. So in the function Restart_Game open a new window
score=window.open('script.php?score=' + game_score, 'gamescore', 'menubar=no,personalbar=no,status=no,toolbar=no,location=no');
script.php saves the $_GET['score'] into the database and shows high score. However, this can be easily cheated.
Corneel@dexternet.nl wrote:
Hi I found a cool javascript game. At the end, the game score wil be set to 0. Before that happens I want it to be possible the user can leave his name and together with the game score,this will be stored in a mysql db with php. I really don't know how to exchange the dat from javascript to php. function Restart_Game() { <?php $db = mysql_connect("localhost","dbname","passwd"); mysql_select_db("dbname",$db); $query = "INSERT INTO dextris (naam, plaats, score, datum, IP) VALUES ('sjaak', 'game_score', '2333', '3-4-2002', '$ipadres')"; $result = mysql_query($query); ?> high_score = (high_score < game_score)?game_score:high_score; game_score = 0; The word game_score is now stored in the db, so the connection works, but now the right game score.... Thanks in advance Corneel van Schie The Netherlands www.dexternet.nl