I want to use a PHP-file to get new scores into MySQL. But it always rounds the float.
I already tried to change the comma to a dot. Didn’t work.
In the MySQL table when manually adding a float with a dot, it works.
This is the essential .PHP part
// Get the user's name and store it
$name = mysqli_escape_string($connection, $_POST['name']);
$name = filter_var($name, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
// Get the user's score and store it
$score = $_POST['score'];
// Create prepared statement
$statement = $connection->prepare("INSERT INTO highscoreTableMySQL (name, score) VALUES (?, ?)");
$statement->bind_param("si", $name, $score);
$statement->execute();
$statement->close();
This is the Unity-Script
public void PostScores(string name, float score)
{
StartCoroutine(DoPostScores(name, score));
}
IEnumerator DoPostScores(string name, float score)
{
WWWForm form = new WWWForm();
form.AddField("name", name);
form.AddField("score", score.ToString().Replace(",", "."));
}
Apart from that, you specify "si" as the parameter types, so you restrict the first parameter to be a string and the second to be an integer. You probably want to use either "sd" or "ss".
I barely use the mysqli interface and just use the standardized PDO interface that php provides. There you usually don’t have to provide type strings and you usually would use named variables inside the query. Though that’s up to you.
Of course there could be other issues on the line. For example what’s the actual datatype of the score column?