-5
我是新來的android和創建一個註冊頁面。由於android不支持mysql,我創建了一個基於php的腳本,它給出了不同查詢的整數值。Android:如果聲明被忽略,即使條件正確
2 --> successful insertion in database
-1 --> Email already used
0--> username used
根據我從php腳本得到的響應的整數值,我執行後續任務。即使在數據庫中成功插入值並且第一個打印站顯示Regresult的值爲「2」,但if語句不起作用,而其他兩個if語句正常工作。
/* Getting the response back from the PHPAPI and storing it in a variable */
HttpEntity entity = Response.getEntity();
String Regresult = EntityUtils.toString(entity);
/* printing value of Regresult to verify if the condition is right or wrong */
System.out.println(Regresult);
/* Registration depending upon response from Http post call */
/* Email used works fine when Regresult = -1 */
if(Regresult.equals("-1"))
{
Context text = getApplicationContext();
CharSequence message = "Email already in use.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(text, message, duration);
toast.show();
}
/* Username used work fine when Regresult = 0 */
else if(Regresult.equals("0"))
{
Context text = getApplicationContext();
CharSequence message = "Username already in use.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(text, message, duration);
toast.show();
}
/* Here is the problem when Regresult= 2 , even though consition is correct the statement don't get executed */
else if(Regresult.equals("2"))
{
Context text = getApplicationContext();
CharSequence message = "Registration Successful.";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(text, message, duration);
toast.show();
System.out.println(Regresult);
}
感謝的作品! –