Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding an 2d html5 canvas game, and trying to connect to a server with javascript in order to create player "highscores."
    primarykey
    data
    text
    <p>After looking around on a Google without any success, i feel posting here may be a good idea as I have used this site to answer previous questions.</p> <p>Anyways, I am currently working on an HTML5 canvas game using; <br/><br/><code>PHP, MYSQL, Html5, and JavaScript</code>.</p> <p>I have <code>MYSQL</code> databases setup and an <code>PHP</code> page displaying player high-scores, and usernames. My question is how would I go about displaying the high-scores inside the canvas once the game is over.<br/><br/> As well as saving the high score when the game ends. I've looked on W3SCHOOLS site about AJAX but I'm still unsure of what codes to use inside the JavaScript file. These are my php/script codes. or at-least the ones that are relevant:</p> <pre><code>// Here's the savescore.php file &lt;?php include 'connect.php'; $user_score = ($_POST['user_score']); $user_name = ($_POST['user_name']); if(mysql_query("INSERT INTO users VALUES('$user_name','$user_score')")) echo "Score Successfully Saved"; else echo "Score Saving Failed"; ?&gt; // Here's some of the index.php file &lt;link rel="stylesheet" href="css.css"&gt; &lt;/HEAD&gt; &lt;body&gt; &lt;div id="menu"&gt; &lt;a class="item" href="/index.php"&gt;Home&lt;/a&gt; &lt;?php include 'connect.php'; session_start(); if($_SESSION['signed_in']) { echo 'Hello ' . $_SESSION['user_name'] . '. Not you? &lt;a href="signout.php"&gt;Sign out&lt;/a&gt;'; include 'chat.php'; } else { echo '&lt;a href="signin.php"&gt;Sign in&lt;/a&gt; or &lt;a href="signup.php"&gt;create an account&lt;/a&gt;.'; } ?&gt; &lt;/div&gt; &lt;BODY&gt; &lt;canvas id="canvasGAMEOVER" width="800" height="599"&gt; &lt;/canvas&gt; &lt;script src="game.js"&gt; &lt;/script&gt; // here's whats inside inside game.js... well the part I want to be able to save score var score = 0; function drawGAMEOVER() { } </code></pre> <p>I have used google and looked at tutorials for AJAX, I found tutorials and answers on how use AJAX using:</p> <pre><code>&lt;form action="savescore.php"&gt; user_name: &lt;input type="text" name="user_name"&gt;&lt;br&gt; user_score: &lt;input type="text" name="user_score"&gt;&lt;br&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code></pre> <p>but I am not sure if its possible to grab the 'user_name' they logged in with (displayed on the index.php page) as well as this.score (displayed inside the javascript file.) Could anyone tell me how this is possible... if not maybe a better way of doing this? Any help/reply is much appreciated thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload