- Home /
My code to php -> sql in PC good, in Android not work. plese fast
On my computer if the code works, but when I run on my android does not work (if I have internet access in the Manifest). here my code C #
public class LoginMenu : MonoBehaviour {
public TextMesh Debugt;
string loginURL = "keep.com.co/DepartamentoDesarrollo/Arthur/ApplicacionMovil/login.php";
string username = "";
string password = "";
string label = "";
void OnGUI() {
//GUI.Window (0, new Rect (Screen.width / 4, Screen.height / 4, Screen.width / 2, Screen.height / 2 - 70), LoginWindow, "Login");
GUI.Label (new Rect (140, 40, 130, 100), "~~~~Username~~~~");
username = GUI.TextField(new Rect(25, 60, 375, 30), username);
GUI.Label (new Rect (140, 92, 130, 100), "~~~~~Password~~~~");
password = GUI.PasswordField (new Rect (25, 115, 375, 30), password, '*');
if(GUI.Button (new Rect (25, 160, 375, 50), "Login")){
StartCoroutine (handleLogin (username, password));}
GUI.Label (new Rect(55, 222, 250, 100), label);
}
void LoginWindow(int windowID) {
}
IEnumerator handleLogin(string username,string password){
string loginURl = this.loginURL + "?username=" + username + "&password=" + password;
WWW loginReader = new WWW (loginURl);
yield return loginReader;
if (loginReader.text == "successsuccess") {
Debug.Log ("correcto"); Debugt.text = "D: "+"Correcto";
}
if (loginReader.text == "successNope") {Debug.Log("incorrecto");Debugt.text = "D: "+"incorrecto"; }
Debug.Log (loginReader);
Debugt.text = "D: "+loginReader.text.ToString();
}
}
help my if for my Job :( ( i need in Android and iOS)
yes this work. example: http://keep.com.co/DepartamentoDesarrollo/Arthur/Applicacion$$anonymous$$ovil/login.php?username=A1&password=A1
this return: success ( A1 and A1 in my data base )
in PC and unity work, in android not return
Answer by Bunny83 · Oct 29, 2014 at 05:29 PM
shouldn't your URL has a scheme? Something like:
string loginURL = "http://keep.com.co/DepartamentoDesarrollo/Arthur/ApplicacionMovil/login.php";
Btw: "does not work" is no description of that happens. Have you checked your "loginReader.error"? Does it contain an error message?
yes this work. example: http://keep.com.co/DepartamentoDesarrollo/Arthur/Applicacion$$anonymous$$ovil/login.php?username=A1&password=A1
this return: success ( A1 and A1 in my data base )
in PC and unity work, in android not return :((
@$$anonymous$$ga: As i said, have you checked "loginReader.error"? If loginReader.text is null or an empty string you probably got some kind of error which you can ready from the loginReader.error property.
At the company i worked we also had a lot server communication for payment, user accounts, game data, ... And we never had a case where you didn't get "anything" from a WWW call.
All your WWW stuff should actually do something like this:
// [...]
WWW loginReader = new WWW (loginURl);
yield return loginReader;
if (!string.IsNullOrEmpty(loginReader.error))
{
Debug.LogError("WWW request has failed: " + loginReader.error);
Debugt.text = "D: "+"WWW request has failed: " + loginReader.error;
}
else if (loginReader.text == "successsuccess")
{
Debug.Log ("correcto"); Debugt.text = "D: "+"Correcto";
}
else if (loginReader.text == "successNope")
{
Debug.Log("incorrecto");Debugt.text = "D: "+"incorrecto";
}
There are hundreds of reasons why a web request might fail. The error returned should at least give you a hint.
@Bunny83 tomorrow i test this. you tested WWW in Android? my proble only in Android :( , i testing in PC return success. in my Android manifest permiss.. to internet conect
@$$anonymous$$ga: Just reinstalled my Android sdk and did a quick testbuild on my nexus. It works fine. It returns the same as when executed in the editor or even when i input the URL in my addressbar. In case of username / password == A1 / A1 i get:
"empiezasi entrasuccesssuccess"
in case i use a wrong password / name i get:
"empiezasi entrasuccessNope"
Note: "empiezasi entrasuccesssuccess" does not equal "successsuccess", obviously. So your code won't work with that data. So do one of these:
change the PHP to only return "successsuccess" or "successNope"
change your C# script to expect "empiezasi entrasuccesssuccess" or "empiezasi entrasuccessNope"
change your C# script to search for the partial string "successsuccess". This however is not recommended since it can be compromised.
I've suggested the changes in order from most likely to not recommended, however all 3 changes would work.
If you don't get "empiezasi entrasuccesssuccess" or "empiezasi entrasuccessNope" at all, again, you should check the error property and display it's content. $$anonymous$$aybe you don't have internet on your Android device? If you are inside a company, they might have strange firewall / router settings for the WLAN. As i said, there are hundreds of possibilities.
Oh man thanks, debug.error return a error, the solution is in android is necesary http:// thanks friend :)