Monday 15 June 2015

android: connecting mysql through php (WAMP setup) - app crashes -



android: connecting mysql through php (WAMP setup) - app crashes -

i new android advise helpful.

i trying connect mysql through php app crashes while trying connect.

private class processlogin extends asynctask<string, string, jsonobject> { private progressdialog pdialog; string email,password; @override protected void onpreexecute() { super.onpreexecute(); inputemail = (edittext) findviewbyid(r.id.email); inputpassword = (edittext) findviewbyid(r.id.pword); email = inputemail.gettext().tostring(); password = inputpassword.gettext().tostring(); pdialog = new progressdialog(login.this); pdialog.settitle("contacting servers"); pdialog.setmessage("logging in ..."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } protected jsonobject doinbackground(string... args) { userfunctions userfunction = new userfunctions(); jsonobject json = userfunction.loginuser(email, password); homecoming json; }

the db_config file like:

define('db_user', "root"); // db user define('db_password', ""); // db password (mention db password here) define('db_database', "aap1"); // database name define('db_server', "localhost"); // db server

i have added table entry in database.

moreover, function calls below:

public jsonobject loginuser(string email, string password){ // building parameters list<basicnamevaluepair> params = new arraylist<basicnamevaluepair>(); params.add(new basicnamevaluepair("tag", custlogin_tag)); params.add(new basicnamevaluepair("email", email)); params.add(new basicnamevaluepair("password", password)); jsonobject json = jsonparser.getjsonfromurl(loginurl, params); homecoming json; } private static string loginurl = "http://127.0.0.1/app1/index.php";

below logcat:

10-07 23:22:40.596: e/buffer error(2003): error converting result java.lang.nullpointerexception: lock == null 10-07 23:22:40.676: e/json parser(2003): error parsing info org.json.jsonexception: end of input @ character 0 of 10-07 23:22:40.766: e/androidruntime(2003): fatal exception: main 10-07 23:22:40.766: e/androidruntime(2003): process: com.example.app1, pid: 2003 10-07 23:22:40.766: e/androidruntime(2003): java.lang.nullpointerexception 10-07 23:22:40.766: e/androidruntime(2003): @ com.example.app1.login$processlogin.onpostexecute(login.java:180) 10-07 23:22:40.766: e/androidruntime(2003): @ com.example.aap1.login$processlogin.onpostexecute(login.java:1) 10-07 23:22:40.766: e/androidruntime(2003): @ android.os.asynctask.finish(asynctask.java:632) 10-07 23:22:40.766: e/androidruntime(2003): @ android.os.asynctask.access$600(asynctask.java:177) 10-07 23:22:40.766: e/androidruntime(2003): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:645) 10-07 23:22:40.766: e/androidruntime(2003): @ android.os.handler.dispatchmessage(handler.java:102) 10-07 23:22:40.766: e/androidruntime(2003): @ android.os.looper.loop(looper.java:136) 10-07 23:22:40.766: e/androidruntime(2003): @ android.app.activitythread.main(activitythread.java:5017) 10-07 23:22:40.766: e/androidruntime(2003): @ java.lang.reflect.method.invokenative(native method) 10-07 23:22:40.766: e/androidruntime(2003): @ java.lang.reflect.method.invoke(method.java:515) 10-07 23:22:40.766: e/androidruntime(2003): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) 10-07 23:22:40.766: e/androidruntime(2003): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) 10-07 23:22:40.766: e/androidruntime(2003): @ dalvik.system.nativestart.main(native method)

json parser follows:

`public jsonobject getjsonfromurl(string url, list<?> params) { // making http request seek { // defaulthttpclient defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url); httppost.setentity(new urlencodedformentity ((list<? extends namevaluepair>) params)); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); } grab (unsupportedencodingexception e) { e.printstacktrace(); } grab (clientprotocolexception e) { e.printstacktrace(); } grab (ioexception e) { e.printstacktrace(); }`

and php script is:

`if ($tag == 'login') { // request type check login $email = $_post['email']; $password = $_post['password']; // check user $user = $db->getuserbyemailandpassword($email, $password); if ($user != false) { // user found // echo json success = 1 $response["success"] = 1; $response["user"]["email"] = $user["email"]; $response["user"]["uname"] = $user["username"]; $response["user"]["uid"] = $user["unique_id"]; $response["user"]["created_at"] = $user["created_at"]; echo json_encode($response); } else { // user not found // echo json error = 1 $response["error"] = 1; $response["error_msg"] = "incorrect email or password!"; echo json_encode($response); }`

and db function is:

` public function getuserbyemailandpassword($email, $password) {         $result = mysqli_query("select * users email = '$email'") or die(mysqli_error());         // check result         $no_of_rows = mysqli_num_rows($result);         if ($no_of_rows > 0) {             $result = mysqli_fetch_array($result);             $salt = $result['salt'];             $encrypted_password = $result['encrypted_password'];             $hash = $this->checkhashssha($salt, $password);             // check password equality             if ($encrypted_password == $hash) {                 // user authentication details right                 return $result;             }         } else {             // user not found             return false;         }    }`

i have tested db connection testmysql.php , fine.

change

list<basicnamevaluepair> params = new arraylist<basicnamevaluepair>();

as list<namevaluepair> params = new arraylist<namevaluepair>();

android mysql

No comments:

Post a Comment