I've recently been working on a fairly complicated game. I've stored information with local storage, but that allows the player to edit it, and does not transfer from computer to computer. The two scripts run on a single server, and I use the following to ping the php server:
function initiateLoginSequence() {
var isnewplayer=prompt("Hello! Are you new?(Y/N)");
if(isnewplayer.equalsIgnoreCase("N")) {
var username = prompt("Enter username.");
var password = prompt("Enter Password.");
//parsing code goes here later.
} else {
var username = prompt("Enter a username. This will be used for future logins.");
var password = prompt("Enter a password. This will be used for future logins.","*");
var req = new XMLHttpRequest();
req.open('POST', 'http://69.144.34.106/Scores.php', true);
req.send("returning=false"+"&name="+username+"&pw="+password+"&level="+lvl+"&save=true");
req.send();
}
}
I then process the results with this:
<?php
$returning=_POST["returning"];
$save=_POST["save"]
$password=_POST["pw"];
$username=_POST["name"];
$score=_POST["lvl"];
$connection=mysql_connect("localhost:3306","****","*****");
if($returning=="false" && $save=="true") {
mysql_select_db("userdata",$connection);
$sqlcmd = "CREATE TABLE ".$username."(
Username varchar(".$username.")
Password varchar(".$password.")
Score varchar(".$score.")
)";
mysql_query($sqlcmd);
} else if($save==false) {
$sqlcmd="SELECT * FROM userdata"
$result = mysql_query($sqlcmd);
while($row=mysql_fetch_array($result)) {
if($row['Username']==$username && $row['Password']) {
echo row['Score'];
}
}
} else if($save==true) {
$sqlcmd="SELECT * FROM userdata"
$result = mysql_query($sqlcmd);
while($row=mysql_fetch_array($result)) {
row['Username']=$username
row['Password']=$Password
row['Score']=$Score
}
}
?>
But after creating the mysql database, nothing is populated. So my basic question is, Am I doing this right? If not, what am I missing?