for my unity game i am trying to make an end score screen where at the end of a level the players imputed name and score are put into a database. i have linked all the game objects correctly but the script doesn't even give an error code and i cant see what i have missed. i have now tried without the adding the score (only adding a imputed name) but i still get the same issue
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class AddScore : MonoBehaviour
{
public InputField nameField;
public GameObject Time;
public GameObject ScoreText;
public Button submitScore;
public void InputScore()
{
StartCoroutine(Register());
}
IEnumerator Register()
{
WWWForm form = new WWWForm();
form.AddField("name", nameField.text);
UnityWebRequest www = UnityWebRequest.Get("https://localhost/sqlconnect/addscore.php");
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.LogError(www.error);
}
else
{
Debug.Log("Score added");
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
}
}
public void VerifyInputs()
{
submitScore.interactable = (nameField.text.Length <= 8);
}
}
i can't tell if it is an issue with the php or the c# code so i put them both up here
<?php
$con = mysqli_connect('localhost', 'root', 'password', 'Leaderboard');
if (mysqli_connect_error())
(
echo"1; Connection failed";
exit()
)
$username = $_POST["name"];
$insertuserquery = "INSERT INTO addscore(username) VALUES ('" . $username . "');";
mysqli_query($con, $insertuserquery) or die("4: Insert addscore query failed");
echo("0")
?>