- Home /
My script for insert a score is not working
I use a script attached to a UI.Button to run a php script in my server. It works fine when i use it for retrieve the scoreboard, but when i try to use into my insert script it just does no work.
Script to access the PHP insertion script:
public string url;
public Text Nome;
public Text Score;
public void Run()
{
StartCoroutine(Gravar());
}
public IEnumerator Gravar()
{
WWW www = new WWW(url+"?name='"+Nome.text+"'&score='"+Score.text+"'");
Debug.Log (www.url);
yield return www;
}
PHP insertion script:
<?PHP
require_once 'app_config.php';
connect();
$Nome = $_GET['name'];
$Score = $_GET['score'];
$query = 'insert into score(score.Nome, score.Score) values('.$Nome.','.$Score.')';
$result = mysql_query($query) or die ('ERRO : ' .mysql_error());
?>
And the PHP script is working, because when i get the url that the console gives me and run it on a browser it work just fine. I can't figure out why its not working in unity.
apart from escaping the single quotes in your php, it should work. did you check whether it's getting to the php and getting the parameters, regardless of posting to mysql or not? that's probably where the problem is.
try returning $result
and printing from unity's debug console.
i've put a echo $result in my php script, and it should return 1 (i've tested in the browser). But my unity does not show anything in de console, not even a empty log.I think that something is giving a error an stopping the script.
i added something very much like your code into a test app (specified my own web server, etc.) and it worked as expected with the php reading the parameters, etc. and unity logging the response.
perhaps some firewall issue with your unity app then?
not sure what else to suggest.
Answer by Marcomini · Dec 17, 2014 at 10:18 AM
I've found the problem, its not on the scripts i've showed. i was using loadlevel immediately after i use the yield www, not giving time for the yield work because it was destroyed in the middle of the process
Your answer
![](https://koobas.hobune.stream/wayback/20220613174157im_/https://answers.unity.com/themes/thub/images/avi.jpg)