php - BasicNetwork.performRequest: Unexpected response code 500, Android Registration System -


i started working on android app , needed login , registration system. found tutorial on androidhive.info errors. i'm using volley library sending http requests , error in logcat related library. used public ip address of server on digitalocean , think might have because in tutorial store php scripts on localhost. android activity used registering users:

package foi.hr.air.asocijacije.ui;  import java.util.hashmap; import java.util.map;  import org.json.jsonexception; import org.json.jsonobject;  import com.android.volley.request.method; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest;  import android.app.activity; import android.app.progressdialog; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; import foi.hr.air.asocijacije.r; import foi.hr.air.asocijacije.db.sqlitehandler; import foi.hr.air.asocijacije.main.appconfig; import foi.hr.air.asocijacije.main.appcontroller; import foi.hr.air.asocijacije.main.mainactivity;  public class registeractivity extends activity {  private static final string tag = registeractivity.class.getsimplename(); private button btnregister; private button btnlinktologin; private edittext inputname; private edittext inputsurname; private edittext inputemail; private edittext inputpassword; private edittext inputpasswordrepeated; private progressdialog pdialog; private sessionmanager session; private sqlitehandler db;  public void oncreate(bundle savedbundleinstance) {     super.oncreate(savedbundleinstance);     setcontentview(r.layout.register);      inputname = (edittext) findviewbyid(r.id.name);     inputsurname = (edittext) findviewbyid(r.id.surname);     inputemail = (edittext) findviewbyid(r.id.email);     inputpassword = (edittext) findviewbyid(r.id.password);     inputpasswordrepeated = (edittext) findviewbyid(r.id.passwordcheck);     btnregister = (button) findviewbyid(r.id.btnregister);     btnlinktologin = (button) findviewbyid(r.id.btnlinktologinscreen);      pdialog = new progressdialog(this);     pdialog.setcancelable(false);      session = new sessionmanager(getapplicationcontext());      db = new sqlitehandler(getapplicationcontext());      if (session.isloggedin()) {         intent intent = new intent(registeractivity.this, mainactivity.class);         startactivity(intent);         finish();     }      btnregister.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub             string name = inputname.gettext().tostring();             string surname = inputsurname.gettext().tostring();             string email = inputemail.gettext().tostring();             string password = inputpassword.gettext().tostring();             string passwordcheck = inputpasswordrepeated.gettext().tostring();              if(name.isempty() || surname.isempty() || email.isempty() || password.isempty() || passwordcheck.isempty()) {                 toast.maketext(getapplicationcontext(), "please enter details", toast.length_long).show();             }             else {                 if (password.equals(passwordcheck)){                     registeruser(name, surname, email, password);                 }                 else {                     toast.maketext(getapplicationcontext(), "passwords don't match", toast.length_long).show();                 }             }         }     });      btnlinktologin.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent = new intent(getapplicationcontext(), loginactivity.class);             startactivity(i);         }     }); }  private void registeruser(final string name, final string surname, final string email, final string password) {        string tag_string_req = "req_register";      pdialog.setmessage("registering...");     showdialog();      stringrequest strreq = new stringrequest(method.post, appconfig.url_register, new response.listener<string>() {         @override         public void onresponse(string response) {             // todo auto-generated method stub             log.d(tag, "register response: " + response.tostring());             hidedialog();              try {                 jsonobject jobj = new jsonobject(response);                 boolean error = jobj.getboolean("error");                 if(!error) {                     string uid = jobj.getstring("uid");                     jsonobject user = jobj.getjsonobject("user");                     string name = user.getstring("name");                     string surname = user.getstring("surname");                     string email = user.getstring("email");                     string created_at = user.getstring("created_at");                      db.adduser(uid, name, surname, email, created_at);                      intent intent = new intent(registeractivity.this, loginactivity.class);                     startactivity(intent);                     finish();                 }                 else {                     string errormsg = jobj.getstring("errormsg");                     toast.maketext(getapplicationcontext(), errormsg, toast.length_long).show();                 }             }             catch (jsonexception e) {                 e.printstacktrace();             }         }     }, new response.errorlistener() {         @override         public void onerrorresponse(volleyerror error) {             // todo auto-generated method stub             log.e(tag, "registration error: " + error.getmessage());             toast.maketext(getapplicationcontext(), error.getmessage(), toast.length_long).show();             hidedialog();         }     }) {         @override         protected map<string, string> getparams() {             // todo auto-generated method stub             map<string, string> params = new hashmap<string, string>();             params.put("tag", "register");             params.put("name", name);             params.put("surname", surname);             params.put("email", email);             params.put("password", password);              return params;         }     };     appcontroller.getinstance().addtorequestqueue(strreq, tag_string_req); }  private void showdialog() {     if (!pdialog.isshowing()) {         pdialog.show();     } }  private void hidedialog() {     if(pdialog.isshowing()) {         pdialog.dismiss();     } } } 

in class appconfig stored path location php scripts (public ip)

package foi.hr.air.asocijacije.main;  public class appconfig {  public static string url_login = "http://95.85.57.105/android_login_api/";  public static string url_register = "http://95.85.57.105/android_login_api/"; } 

and error log i'm getting in logcat

04-29 11:35:18.440: e/volley(1742): [180] basicnetwork.performrequest:   unexpected response code 500 http://95.85.57.105/android_login_api/ 04-29 11:35:18.916: e/registeractivity(1742): registration error: null 

i hope can me thing right, tried using post method on mozilla plugin httprequester try store data in online mysql database sure php scripts working fine, don't know content should send in json format. if needed post additional data understand problem is.

isn't supposed be

public static string url_login = "http://95.85.57.105/android_login_api/login.php";  public static string url_register = "http://95.85.57.105/android_login_api/register.php"; 

im not sure whether error thrown 404 or 500 , still give try.

edit: (updated on 9th december 2015)

first thing's first . problem 500 error server error , problem can resolved checking logs first . go android_login_api folder in server , add these 2 lines

error_reporting(-1); ini_set('display_errors', 'on'); 

now android studio show error log , problem is. faced same problem , after viewing error , problem database connectivity. if still find problem persisting can use postman or restapi client extension in google , check whether given url working on server . should help.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -