mysql - Displaying/passing PHP data inside javascript -


after looking around on google without success, feel posting here may idea have used site answer previous questions.

anyways, working on html5 canvas game using;

php, mysql, html5, , javascript.

i have mysql databases setup , php page displaying player high-scores, , usernames. question how go displaying high-scores inside canvas once game over.

saving high score when game ends. i've looked on w3schools site ajax i'm still unsure of codes use inside javascript file. these php/script codes. or at-least ones relevant:

// here's savescore.php file                <?php                    include 'connect.php';              $user_score = ($_post['user_score']);             $user_name = ($_post['user_name']);                  if(mysql_query("insert users values('$user_name','$user_score')"))                     echo "score saved";                 else                     echo "score saving failed";             ?>   // here's of index.php file             <link rel="stylesheet" href="css.css">             </head>             <body>                      <div id="menu">                       <a class="item" href="/index.php">home</a>               <?php              include 'connect.php';             session_start();                     if($_session['signed_in'])                   {                       echo 'hello ' . $_session['user_name'] . '. not you? <a href="signout.php">sign out</a>';                       include 'chat.php';                 }                   else                   {                       echo '<a href="signin.php">sign in</a> or <a href="signup.php">create account</a>.';                   }                  ?>                 </div>             <body>             <canvas id="canvasgameover" width="800" height="599"> </canvas>              <script src="game.js"> </script>  // here's whats inside inside game.js... part want able save score             var score = 0;             function drawgameover() {                 } 

i have used google , looked @ tutorials ajax, found have been able connect server using ajax using:

<form action="savescore.php">   user_name: <input type="text" name="user_name"><br>   user_score: <input type="text" name="user_score"><br>   <input type="submit" value="submit"> </form> 

inside index.php page, not sure if possible grab 'user_name' logged in (displayed on index.php page) this.score (displayed inside javascript file.) tell me how possible... if not maybe better way of doing this? help/reply appreciated in advance.

if using jquery can use $.get highscores.

http://api.jquery.com/jquery.get/


Comments