0
我正在開發一個小應用程序,並且需要進行身份驗證。我試圖通過php連接到MYsql db來開發。Android通過php遠程連接Mysql數據庫 - 登錄身份驗證
添加uname/pw - > loging - >發送到php - > check db - > ok發送回到android - > authenticated。 /錯誤發回重新登錄。
我已經開發到目前爲止,我認爲這是應該如何,但我不確定,因爲我真的是新的cording。
請善待我的幫助。謝謝。
public class Loging extends Activity{
TextView txt;
EditText uname,pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.loging);
Button b = (Button)findViewById(R.id.log);
uname = (EditText)findViewById(R.id.uname);
pwd = (EditText)findViewById(R.id.pwd);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", uname.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Pass", pwd.getText().toString()));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.helloworld.com/report.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
}
catch(Exception e)
{
Log.e("log_tag","Error in http connection"+e.toString());
}
}
});
}
}
什麼是你真正的錯誤?它是否成功登錄...或不是? –
它沒有給出任何錯誤......我創建了這個以及谷歌幫助,我不知道如何編寫php代碼以及連接到Mysql數據庫 –