- Home /
Need help to get my www.form to work.
hey gang trying to WWW call a PHP script on me server don't see any errors on my unity script yet cant get a response from the website, and can't seem to get it to work. everything is in the right directories keep getting Debug.Log("Error Saving Your Game..." + www.text); so as far as i can see its not even being sent to the php on my site.
cant see what the error is...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Photon.Pun.Demo.AsteroidsGame
{
public class AccountConnect : MonoBehaviour
{
public string UserName;
public string Password;
public float Xp = 10;
public float XpMaax = 1000;
public float Level = 1;
public float MaxLevel = 90;
public float Crystals = 10;
public float Titanium = 10;
public float StarFighter01;
public float StarFighter02;
public float StarFighter03;
public float StarFighter04;
public float StarFighter05;
public string FinaleFileName;
public bool succssfulLogin = true;
public void NewGameData()
{
StartCoroutine(NewGameSave());
FinaleFileName = UserName + Password;
}
// Use To Save Any Data... :)
public void SaveGameData()
{
StartCoroutine(sendTextToFile());
}
//Also Use For Loggin
public void LoadGameDataButton()
{
StartCoroutine(LoadGameData());
FinaleFileName = UserName + Password;
}
//NewGameData...................
IEnumerator NewGameSave()
{
bool succssful = true;
WWWForm form = new WWWForm();
form.AddField("UserName", FinaleFileName);
form.AddField("Experiancepoints", "0");
form.AddField("Level", "1");
form.AddField("Crystals", "1100");
form.AddField("Titanium", "1100");
form.AddField("StarFighter01", "1");
form.AddField("StarFighter02", "0");
form.AddField("StarFighter03", "0");
form.AddField("StarFighter04", "0");
form.AddField("StarFighter05", "0");
WWW www = new WWW("http://www.darkdivideonline.com/savegames/savedata.php", form);
yield return www;
if (www.error != null)
{
succssful = true;
Debug.Log("We Got This..." + www.text);
}
else
{
succssful = false;
Debug.Log("Error..." + www.text);
}
}
//Save Game Data...................
IEnumerator sendTextToFile()
{
bool succssful = true;
WWWForm form = new WWWForm();
form.AddField("UserName", FinaleFileName);
form.AddField("Experiancepoints", Xp.ToString());
form.AddField("Level", Level.ToString());
form.AddField("Crystals", Crystals.ToString());
form.AddField("Titanium", Titanium.ToString());
form.AddField("StarFighter01", "1");
form.AddField("StarFighter02", StarFighter02.ToString());
form.AddField("StarFighter03", StarFighter03.ToString());
form.AddField("StarFighter04", StarFighter04.ToString());
form.AddField("StarFighter05", StarFighter05.ToString());
WWW www = new WWW("http://www.darkdivideonline.com/savegames/savedata.php", form);
yield return www;
if(www.error != null)
{
succssful = true;
}
else
{
Debug.Log("Error Saving Your Game..." + www.text);
succssful = false;
}
}
// Load Data...................
IEnumerator LoadGameData()
{
WWWForm formload = new WWWForm();
formload.AddField("UserName", FinaleFileName);
WWW www = new WWW("http://www.darkdivideonline.com/loaddata.php", formload);
yield return www;
if (www.error != null)
{
succssfulLogin = true;
}
else
{
Debug.Log("Error Saving Your Game..." + www.text);
succssfulLogin = false;
}
}
}
}
PHP:
$text1 = $_POST["UserName"];
$text2 = $_POST["Experiancepoints"];
$text3 = $_POST["Level"];
$text4 = $_POST["Crystals"];
$text5 = $_POST["Titanium"];
$text6 = $_POST["StarFighter01"];
$text7 = $_POST["StarFighter02"];
$text8 = $_POST["StarFighter03"];
$text9 = $_POST["StarFighter04"];
$text10 = $_POST["StarFighter05"];
if($text1 != "")
{
echo("Message Successfully Sent YAY!!!");
$file = fopen("$text1.txt","w");
fwrite($file , $text2);
fwrite($file , $text3);
fwrite($file , $text4);
fwrite($file , $text5);
fwrite($file , $text6);
fwrite($file , $text7);
fwrite($file , $text8);
fwrite($file , $text9);
fwrite($file , $text10);
fclose($file);
}else{
echo("Mesasage Not Deliverd....");
}
?>
First of all your error checking is the wrong way round:
if (www.error != null)
{
succssful = true;
Debug.Log("We Got This..." + www.text);
}
else
{
succssful = false;
Debug.Log("Error..." + www.text);
}
You set succesful to true when there is an error and set it to false when there isn't an error. Also in both cases you lof www.text which makes no sense. if error is set it actually contains the error message. So if error is != null you want to actually print that error message.
heya, thanks for a start, didn't even notice that, I'm not getting any error messages and it says that the script works, yet on my server nothing seems to be happening and no files are being created / written.
Your answer
Follow this Question
Related Questions
Problem with online high score 4 Answers
send xml with wwwform for youtube video upload from unity 0 Answers
Passing a curl user via WWWForm 1 Answer
Returning from Coroutine stops the Update() method. 0 Answers
Coroutine for WWW call not resuming 0 Answers