Reputation: 107
I need some guide in data format/syntax with php.
I have a simple form in my app, so user should fill the form and submit, Am successfully uploading my text file to my server, but need some good format.
Here is my code
[Header("Input Fields")]
public InputField userName;
public InputField mobileNo;
public InputField coinsToRedeem;
[Header("Data Strings")]
public string usernameText;
public string mobileNoText ;
public string coinsText;
public void GetSetData()
{
usernameText = userName.text;
mobileNoText = mobileNo.text;
coinsText = coinsToRedeem.text;
StartCoroutine(UpLoadUserData());
}
IEnumerator UpLoadUserData()
{
WWWForm form = new WWWForm();
form.AddField("name", usernameText);
form.AddField("data", mobileNoText +","+ coinsText);
UnityWebRequest www = UnityWebRequest.Post("https://myserver/UserData.php", form);
yield return www.SendWebRequest();
if (www.isNetworkError)
Debug.Log(www.error);
else
Debug.Log("Uploaded");
}
PHP CODE
<?php
if(isset($_POST['name']) && isset($_POST['data'])){
file_put_contents($_POST['name'].".txt", $_POST['data']);
echo "uploaded.";
}else{
echo "invalid file uploaded.";
}
?>
So now the data text file is uploading, and in the text i got the data like this format "Mobile Number, Number of coins"
But i need below format "Mobile Number number of coins" So, how can i write like this? Or how to add more fields? thanks.
Upvotes: 0
Views: 1326
Reputation: 79
form.AddField("data", mobileNoText +","+ coinsText);
this is where you format your data as "Mobile Number, Number of coins"
if you change it to something like
form.AddField("data", mobileNoText + coinsText);
it will write Mobile Number number of coins.
Upvotes: 2