私はアンドロイドが初めてで、登録ページを作成しています。android は mysql をサポートしていないため、さまざまなクエリに対して整数値を提供する php ベースのスクリプトを作成しました。
2 --> successful insertion in database
-1 --> Email already used
0--> username used
PHP スクリプトから取得した応答の整数値に応じて、後続のタスクを実行します。データベースに値を正常に挿入し、最初の印刷ステートメントで Reresult の値が「2」と表示されても、if ステートメントが機能せず、else 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);
}