I´m trying to save data from a unity game in an sql database, to then be displayed on a website. I´ve found free hosting for both the database and website. So far the website works fine and is able to connect to the db and display already existing data. Now i want to connect the unity app to the db so i can save a player´s name and their highscore. I´m using a c# script to send data to a php script through UnityWebRequest (this is the proper way as far as I know), and from there using POST and a query to check for existing entries and adding new ones/updating old ones.
//Data provided by user
$user = $_POST["user"];
$points = $_POST["points"];
//Query
$sql = "SELECT * FROM scores WHERE name = " . $user;
//$sql2 =
//$sql3 =
$result = $db->query($sql);
//$result2 = $db->query($sql2);
//$result3 = $db->query($sql3);
//If name exists, change existing points, else new entry
if ($result->num_rows > 0) {
"UPDATE scores SET score = . $points WHERE score < . $points AND name = " . $user;
} else {
"INSERT INTO scores VALUES (. $user, . $points)";
}
The main question is, does the php work for what I´m trying to do and is the way I´m doing this ok or should I do something differently? Also how do you recommend I host the php file?
Edit: So far, I´m returning a 400 Bad Request in my unity console