I cant seem to work out how to simply add a javascript variable into a mySQL table!
I have a html code which is just making a canvas for my game. I then have a javascript file doing all the game proccess and here is the code i am using to send the javascript variable to a php file:
var uiStats = $("#gameStats");
var uiHealth = $(".gameHealth");
var health = 10;
$.post('http:/localhost/basic_structure/game.php', { "health" : health});
Then here is the php file to insert the data into the database:
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die
('Error connecting to mysql');
$dbname = 'game';
mysql_select_db($dbname, $conn);
$health = $_POST['health'];
mysql_query("INSERT INTO game_table (health)
VALUES ('$health')");
mysql_close($con);
I simply just want to save the health of the player in my game for later uses.
Any help is appreciated
Thanks