android app通過php API串連資料庫實現註冊問題

來源:互聯網
上載者:User
關鍵字 app php android 資料庫
appphpandroid資料庫

$conn = mysql_connect("localhost", "root", "root");
?>

require 'conn.php';

if($_POST['username']!=""&&$_POST['password']!="")
{
$password=md5($_POST['password']);
$sql="select * from 'user' where username='$_POST[username]'";
$query=mysqli_query($conn,$sql);
$row=mysqli_num_row($query);
if($row==0){
$sql2="insert into 'user' (username,password) values('$_POST[username]','$password')";
$query=mysqli_query($conn,$sql2);
$result=array("status"=>"success");
echo json_encode($result);
}
else{
$result=array("status"=>"exists");
echo json_encode($result);
}
}

?>

public class register extends Activity{

@Overrideprotected void onCreate(Bundle savedInstanceState) {    // TODO Auto-generated method stub    super.onCreate(savedInstanceState);    CustomTitle ct= new CustomTitle();    ct.getTitleBar(this, "ע��",R.drawable.oval,R.drawable.oval,"����","ȡ��");    setContentView(R.layout.signup);    Button button1=(Button)findViewById(R.id.button1);    final EditText editText1=(EditText)findViewById(R.id.editText1);    final EditText editText2=(EditText)findViewById(R.id.editText2);    button1.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            // TODO Auto-generated method stub            String username=editText1.getText().toString();            String password=editText2.getText().toString();            if(username.equals("")||password.equals("")){                 Toast.makeText(register.this, "使用者名稱或密碼不可為空", Toast.LENGTH_LONG);            }            else{                AsyncHttpClient client=new AsyncHttpClient();                RequestParams params=new RequestParams();                params.add("username",username);                params.add("password",password);                client.post("http://192.168.1.203/NewsDemo/register.php",params,new AsyncHttpResponseHandler() {                    @Override                    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {                        // TODO Auto-generated method stub                        String response=new String();                        Log.e("debug",response);                        JSONObject object=null;                        try {                            object=new JSONObject(response);                            String status=object.getString("status");                            if(status.equals("exists")){                                Toast.makeText(register.this, "使用者名稱已存在,請更換", Toast.LENGTH_LONG);                                }else if(status.equals("error")){                                    Toast.makeText(register.this, "出現錯誤請稍後重試", Toast.LENGTH_LONG);                                }                                else{                                    App.isLogin=true;                                    Intent intent=new Intent(register.this,MainActivity.class);                                    startActivity(intent);                                    register.this.finish();                                }                        } catch (JSONException e) {                            // TODO Auto-generated catch block                            e.printStackTrace();                        }                    }                    @Override                    public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {                        // TODO Auto-generated method stub                        Toast.makeText(register.this, "網路錯誤", Toast.LENGTH_LONG);                    }                });            }        }    });}

}

請問這段代碼有什麼問題嗎 我按註冊鍵也就是button1 沒有反應 資料庫log有收到資訊 沒有反饋
92.168.1.203 - - [28/Feb/2016:22:47:44 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:47:45 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:47:45 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:47:47 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:47:47 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:49:31 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:49:32 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"
192.168.1.203 - - [28/Feb/2016:22:49:34 +0800] "POST /NewsDemo/register.php HTTP/1.1" 200 297 "-" "-"

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.