Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nathanvj · Oct 24, 2019 at 12:26 PM · webwebrequestphprequest

UnityWebRequest Post Not Returning Anything

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;
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathanvj · Oct 24, 2019 at 12:30 PM 0
Share

PS. Already tested the API in Postman (API-testing software) and it's working.

avatar image WarmedxMints nathanvj · Oct 24, 2019 at 12:41 PM 0
Share

Check your console buttons. On top right corner there are 3 buttons, maybe you have logs disabled.

avatar image nathanvj WarmedxMints · Oct 24, 2019 at 12:49 PM 0
Share

Was one of the first things I checked. The "Sending now!" get's printed though.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by xxmariofer · Oct 24, 2019 at 01:52 PM

IEnumerator doesnt continue after the yield return if your object is disable/destroyed, are you maybe disabeling it? can you try using this code and check if the issue it is that is not done, or simply not coninue after the request? (just remove the yield from the request and add the while)

 www.SendWebRequest();
 
 while(!www.isDone)
 {
    Debug.Log("is waiting");
    yield return null;
 }

 Debug.Log("done!");

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathanvj · Oct 24, 2019 at 03:30 PM 0
Share

@xxmariofer, you're a legend. The IEnumerator was indeed attached to a GameObject which state was changing. I put it on a seperate GameObject and now it's working. Thank you so much.

avatar image xxmariofer nathanvj · Oct 24, 2019 at 09:36 PM 0
Share

You are welcome, mark it as correct answer for future readers :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

JSON WebRequest works in 2018.2, throws 403 error in 2018.3 0 Answers

Send Data From C# to PHP Server 0 Answers

Invoke www.error in PHP 1 Answer

UnityWebRequest POST to PHP not work 1 Answer

Get echo output from PHP script which is on an FTP server with C# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges