- Home /
PHP POST through $_REQUEST with WEBBUILD
Hi, i have app, that using php to store and use data from MySQL. All working fine in PC build and in editor play mode. But when i'm using Webbuild - application give nosing to PHP script. That is seem like webbuild can't give POST data, or i do something wrong. Anyway, there's C#:
public IEnumerator SendDataToWeb(string answer, string id){
if (coroutineInProcess == false){
coroutineInProcess = true;
WWWForm form = new WWWForm();
form.AddField( "UserID", id);
form.AddField( "Answer", answer );
//wwwSendData get his value in diferent part of code
WWW download = new WWW( wwwSendData, form );
yield return download;
if(!string.IsNullOrEmpty(download.error))
{
Debug.Log ( "Error downloading: " + download.error );
} else {
Debug.Log ( download.text );
}
coroutineInProcess = false;
}
}
And there's php:
<?php
$userID = $_REQUEST['UserID'];
$answer = $_REQUEST['Answer'];
$host = 'localhost';
$user = 'testUser';
$password = '123qweasd';
$db = 'testdb';
$table = 'highscores';
mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db($db);
$password = md5($password);
mysql_query("DELETE FROM `answers` WHERE TO_DAYS(NOW())- TO_DAYS(dateValue) = 0 AND ID = '{$userID}' ") or die (mysql_error());
mysql_query("INSERT INTO `answers` (ID, answer) VALUES ('{$userID}', '{$answer}')") or die (mysql_error());
echo "Done";
?>
I adeed crossdomain.xml in root of my site. I Test all this stuff on denwer. Repeat: all working, exept post data from web build. In PC build and editor play mode all work without problems.
Sorry for bad knowlege of English.
Comment
Answer by Manveru · May 13, 2015 at 09:25 AM
For now, im using handmaded strings. I add strings to URL like this:
public IEnumerator SendDataToWeb(string answer, string id){
if (coroutineInProcess == false){
coroutineInProcess = true;
Debug.Log (answer);
string getRequest1 = "UserID="+id;
string getRequest2 = "&Answer="+answer;
WWW download = new WWW( wwwSendData+"?"+getRequest1+getRequest2);
yield return download;
if(!string.IsNullOrEmpty(download.error)) {
Debug.Log ( "Error downloading: " + download.error );
} else {
Debug.Log ( download.text );
}
coroutineInProcess = false;
}
}
I's working, but I'm not shure that this is safe and right...