尝试使用volley连接到mysql

问题描述 投票:0回答:1

您好我正在尝试使用齐射库连接到mysql数据库,我已设置post方法以发出请求。

但我在尝试请求时收到(-1)值,所以我不知道问题的确切位置。

但我在尝试请求时收到(-1)值,所以我不知道问题的确切位置。

save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog = new ProgressDialog(Login.this);
                dialog.setMessage("please wait...");
                dialog.setCancelable(true);
                dialog.show();

                if (validateEmail()) {

                    if (validatePassword()) {

                       // Toast.makeText(Login.this, email.getText()+" "+pass.getText(), Toast.LENGTH_SHORT).show();
                        String url = "......";
                        StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                Log.e("LPC", response.toString());
                                if (response.equals("1")) {
                                    SharedPreferences.Editor editor = sharedPref.edit();
                                    editor.putString("email",email.getText().toString());
                                    editor.putString("pass",pass.getText().toString());
                                    editor.commit();
                                    Intent intent = new Intent(Login.this , com.example.fahad.finalyearprojectlayout.MainActivity.class);
                                    startActivity(intent);
                                    finish();
                                }
                                else{
                                    Toast.makeText(Login.this, "Wrong Credentials", Toast.LENGTH_SHORT).show();
                                    dialog.cancel();
                                }
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Log.e("LPC", error.toString());
                                dialog.cancel();
                            }
                        }) {
                            public Map<String, String> getParams() {
                                Map<String, String> params = new HashMap<>();
                                params.put("email", email.getText().toString());
                                params.put("pass", pass.getText().toString());
                                params.put("last", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date().getTime()).toString());
                                return params;
                            }
                        };
                        queue.add(stringRequest);

                    } else {
                        ErrorDialog("Invalid Password");
                    }
                } else {
                    ErrorDialog("Invalid Email\nInvalid Password");
                }
            }
        });

enter image description here

logcat的

    2018-10-20 16:17:19.323 1680-1734/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 50052543 , only wrote 50052240
2018-10-20 16:17:19.352 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.355 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.360 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.363 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.412 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.430 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.444 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.448 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:19.460 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:20.152 6900-6900/com.example.yousaf.finalyearprojectlayout E/LPC: -1
2018-10-20 16:17:20.156 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:20.214 2059-3071/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@6a0cab9 attribute=null, token = android.os.BinderProxy@789f7dd
2018-10-20 16:17:20.226 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:20.230 6900-6919/com.example.yousaf.finalyearprojectlayout D/EGL_emulation: eglMakeCurrent: 0xa1d04060: ver 3 0 (tinfo 0xa1d032c0)
2018-10-20 16:17:20.390 1344-1344/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
2018-10-20 16:17:22.159 2059-2059/system_process W/WindowManager: Attempted to remove non-existing token: android.os.Binder@5dfefbd
2018-10-20 16:17:22.549 1680-1735/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 50359892 , only wrote 50207040
2018-10-20 16:17:27.275 1344-1368/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2018-10-20 16:17:27.280 1344-1395/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 1536000

服务器端代码

    <?php


mysqli_connect("fdb22.awardspace.net","2853850_mydb","0000000000Abc");//change server name  //pass username according your settings


$conn = mysqli_connect("myhost","user","pass","dbname");

mysqli_select_db($conn,'2853850_mydb');




$email=$_POST['email'];
$pass=$_POST['pass'];
$last=$_POST['last'];


$sql1="update bts set last_login = '$last'  where email = '$email' and pass = '$pass'";

if (!$sql1) {

echo "Could not successfully run query ($sql) from DB: " . mysqli_error();

exit;

}
else
{
echo(mysqli_affected_rows($conn));
}

mysqli_close($conn);


?>

解决这个问题的任何解决方案。

谢谢

android mysql
1个回答
0
投票

使用,在PHP文件中执行查询,

$query = mysqli_query($conn, $sql1);

if(!$query) {
 //query not executed
}
else {
 //return no of row affcted
}
© www.soinside.com 2019 - 2024. All rights reserved.