Search Unity

Trouble updating from WWW to UnityWebRequest

Discussion in 'Editor & General Support' started by minecraftgoldmad, Aug 8, 2019.

  1. minecraftgoldmad

    minecraftgoldmad

    Joined:
    Aug 8, 2019
    Posts:
    8
    i was going through an old tutorial showing how to use unity and php to link to an sql database and then i went into unity and it said WWW is obselete and i can't get it to work with webrequest. i am making a script so people can register and i am not sure how to use webrequest and wwwform together
    here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using UnityEngine.UI;
    6.  
    7. public class Register : MonoBehaviour
    8. {
    9.     public InputField NameInput;
    10.     public InputField EmailInput;
    11.     public InputField PasswordInput;
    12.     void CallRegister()
    13.     {
    14.         StartCoroutine(RegisterAccount());
    15.     }
    16.  
    17.  
    18.  
    19.     IEnumerator RegisterAccount()
    20.     {
    21.         WWWForm form = new WWWForm();
    22.         form.AddField("name", NameInput.text);
    23.         form.AddField("email", EmailInput.text);
    24.         form.AddField("password", PasswordInput.text);
    25.         using (UnityWebRequest www = UnityWebRequest.Get("http://localhost/sqlconnect/register.php", form))
    26.         {
    27.             yield return www.Send();
    28.             Debug.Log(www.downloadHandler.text);
    29.  
    30.         }
    31.     }
    32. }
    33.  
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,854
    i think you need to use UnityWebRequest.Post()
    usually get parameters would go into the url

    from server you can also check if the variables are set or not, and then print errors.
     
  3. minecraftgoldmad

    minecraftgoldmad

    Joined:
    Aug 8, 2019
    Posts:
    8
    is there a way i can use post and then echo back something from the php file?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    5,854
  5. minecraftgoldmad

    minecraftgoldmad

    Joined:
    Aug 8, 2019
    Posts:
    8
    i already set it up in the php file to echo the request but how do i get the echo into unity
     
unityunity