- Home /
WWW form isn't working in Build
I finally finish my project or so I think. Currently it is set up to run as two parts: a unity standalone and a php/mysql on a localhost. I made a development build, launched the server and ran it. I got to the login screen, typed in my info and hit submit. NOTHING!
Does the build version need something else to run properly? Thanks!
Answer by Gilead7 · Jul 11, 2019 at 05:39 PM
I tried a couple more tutorials to no avail, then I looked at an example on the API Scripting reference and found the answer! If any of you are having the same issue, here's how you solve it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking; Make sure to add this!
using System;
public class GetDate : MonoBehaviour
{
public Text DateText;
// Use this for initialization
void Start()
{
StartCoroutine(Upload());
}
IEnumerator Upload()
{
string IDField = "123456"; This is the id that will be sent via the wwwform
DateTime DateField = DateTime.Now;
string ServiceDate = DateField.ToString ();
WWWForm form = new WWWForm(); Initialize a new WWWForm called form
form.AddField("ID",IDField); Like JSON, this has a key and the data to be added to it
form.AddField("Date", ServiceDate);
UnityWebRequest www = UnityWebRequest.Post("http://localhost/Test/GetDate.php", form);
yield return www.SendWebRequest(); This is the new part. Out in the path to your own script
Debug.Log (www);
if(www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error); This will show any error. If it's an unknown generic error, check the path, it may not point to the right script.
}
else
{
Debug.Log(www.downloadHandler.text); This will show whatever php echos out.
DateText.text = www.downloadHandler.text; This simply showed it onscreen. If you use this, make sure to use a new wait for seconds (yield return new WaitForSeconds(2);) in the coroutine. Then set the Text.text to "".
}
}
}
I hope this helps someone else out in UnityLand!
Your answer
Follow this Question
Related Questions
WWWForm always returning Internal Server Error 1 Answer
WebHosting with phpMyAdmin PHP 0 Answers
Is it possible to send a table name through a wwwform and use it in a php query? 0 Answers
WWWForm Question 2 Answers
Multistage Delete with WWW 1 Answer