The player gets registered in the database succesfully but it seems like the code after 'yield return www.SendWebRequest()' is never executed. Not a single Debug.Log() is showing up in my console.
Can someone please help me out?
C# code: private IEnumerator Register() { WWWForm form = new WWWForm(); form.AddField("name", "Anonymous"); form.AddField("highscore", "0"); Debug.Log("Sending now!"); UnityWebRequest www = UnityWebRequest.Post(API_URL + REGISTER_PAGE, form); yield return www.SendWebRequest(); // These debug.logs don't show in console, but the player is added to the database without any issues. if (www.isNetworkError || www.isHttpError) { Debug.LogError("There was an error: " + www.error); } else { Debug.Log("Registered succesfully."); string name = www.downloadHandler.text; PlayerPrefs.SetString("name", name); } }
PHP code: include("../connection.php"); $name = $_POST["name"]; $highscore = $_POST["highscore"]; $stmt = $connection->prepare("SELECT MAX(ID) FROM Leaderboard"); $stmt->execute(); $last_id = $stmt->fetchColumn(); if($name === "Anonymous") { if($last_id == false) { $last_id = 0; } else { $last_id = ((int)$last_id); $last_id++; } $name = ($name."[".$last_id."]"); } $stmt = $connection->prepare("INSERT INTO Leaderboard (name, highscore) VALUES (:name, :highscore)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':highscore', $highscore); $stmt->execute(); echo $name; $connection = null;
Can someone please help me out?
C# code: private IEnumerator Register() { WWWForm form = new WWWForm(); form.AddField("name", "Anonymous"); form.AddField("highscore", "0"); Debug.Log("Sending now!"); UnityWebRequest www = UnityWebRequest.Post(API_URL + REGISTER_PAGE, form); yield return www.SendWebRequest(); // These debug.logs don't show in console, but the player is added to the database without any issues. if (www.isNetworkError || www.isHttpError) { Debug.LogError("There was an error: " + www.error); } else { Debug.Log("Registered succesfully."); string name = www.downloadHandler.text; PlayerPrefs.SetString("name", name); } }
PHP code: include("../connection.php"); $name = $_POST["name"]; $highscore = $_POST["highscore"]; $stmt = $connection->prepare("SELECT MAX(ID) FROM Leaderboard"); $stmt->execute(); $last_id = $stmt->fetchColumn(); if($name === "Anonymous") { if($last_id == false) { $last_id = 0; } else { $last_id = ((int)$last_id); $last_id++; } $name = ($name."[".$last_id."]"); } $stmt = $connection->prepare("INSERT INTO Leaderboard (name, highscore) VALUES (:name, :highscore)"); $stmt->bindParam(':name', $name); $stmt->bindParam(':highscore', $highscore); $stmt->execute(); echo $name; $connection = null;