php - Android Sign Up Activity not inserting data remote MySQL database from user input -
i've been having trouble updating remote database. signuprrequest class exists extends string request class.
package com.example.admin.tripod; import com.android.volley.response; import com.android.volley.toolbox.stringrequest; import java.util.hashmap; import java.util.map; /** * created admin on 4/19/2016. */ public class signuprequest extends stringrequest { private static final string register_request_url = "http://lushandlaceng.com/php/register.php"; private map<string, string> params; public signuprequest(string fullname, string email, string username, string password, string dob, response.listener<string> listener) { super(method.post, register_request_url, listener, null); params = new hashmap<>(); params.put("fullname", fullname); params.put("email", email); params.put("username", username); params.put("password", password); params.put("dob", dob); } @override public map<string, string> getparams() { return params; } }
the sign activity page uses volley library , has following code createan instance of signuprequest class , queue it.
package com.example.admin.tripod; import android.app.alertdialog; import android.app.datepickerdialog; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.view.windowmanager; import android.widget.button; import android.widget.datepicker; import android.widget.edittext; import com.android.volley.requestqueue; import com.android.volley.response; import com.android.volley.toolbox.volley; import org.json.jsonexception; import org.json.jsonobject; import java.text.simpledateformat; import java.util.calendar; import java.util.locale; public class signupactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_sign_up); final edittext infname = (edittext) findviewbyid(r.id.txtfnamesignup); final edittext inemail = (edittext) findviewbyid(r.id.txtemailsignup); final edittext inuser = (edittext) findviewbyid(r.id.txtusersignup); final edittext indob = (edittext) findviewbyid(r.id.txtdobsignup); final edittext inpassword = (edittext) findviewbyid(r.id.txtpasswordsignup); final edittext inconfirm = (edittext) findviewbyid(r.id.txtcpasswordsignup); final button bsignup = (button) findviewbyid(r.id.signupbutton); final calendar mycalendar = calendar.getinstance(); final datepickerdialog.ondatesetlistener date = new datepickerdialog.ondatesetlistener() { @override public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { // todo auto-generated method stub mycalendar.set(calendar.year, year); mycalendar.set(calendar.month, monthofyear); mycalendar.set(calendar.day_of_month, dayofmonth); string myformat = "yyyy-mm-dd"; //in need put here simpledateformat sdf = new simpledateformat(myformat, locale.us); indob.settext(sdf.format(mycalendar.gettime())); if(inpassword.requestfocus()) { getwindow().setsoftinputmode(windowmanager.layoutparams.soft_input_state_always_visible); } } }; indob.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub new datepickerdialog(signupactivity.this, date, mycalendar .get(calendar.year), mycalendar.get(calendar.month), mycalendar.get(calendar.day_of_month)).show(); } }); ///registration bsignup.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { final string fullname = infname.gettext().tostring(); final string email = inemail.gettext().tostring(); final string username = inuser.gettext().tostring(); final string password = inpassword.gettext().tostring(); final string dob = indob.gettext().tostring(); response.listener<string> responselistener = new response.listener<string>() { @override public void onresponse(string response) { try { jsonobject jsonresponse = new jsonobject(response); boolean success = jsonresponse.getboolean("success"); if (success) { alertdialog.builder builder = new alertdialog.builder(signupactivity.this); builder.setmessage("register success") .create() .show(); intent intent = new intent(signupactivity.this, loginactivity.class); signupactivity.this.startactivity(intent); } else { alertdialog.builder builder = new alertdialog.builder(signupactivity.this); builder.setmessage("register failed") .setnegativebutton("retry", null) .create() .show(); } } catch (jsonexception e) { e.printstacktrace(); } } }; signuprequest registerrequest = new signuprequest(fullname, email, username, password, dob, responselistener); requestqueue queue = volley.newrequestqueue(signupactivity.this); queue.add(registerrequest); } }); } }
the php code procsses requests has following code;
<?php $con = mysqli_connect("xxx", "yyy", "zzz", "lushandl_tripodtest"); $fullname = $_post["fullname"]; $email = $_post["email"]; $username = $_post["username"]; $password = $_post["password"]; $dob = $_post["dob"]; $statement = mysqli_prepare($con, "insert user (fullname, email, username, password, dob) values (?, ?, ?, ?, ?)"); mysqli_stmt_bind_param($statement, "sssss", $fullname, $email, $username, $password, $dob); mysqli_stmt_execute($statement); $response = array(); $response["success"] = true; echo json_encode($response); ?>
on running app returns alert process successful , moves login page. however, when check database, no changes have been made.
please identify problem be.
code adapted from: https://www.youtube.com/watch?v=t7z4gvfat4a
Comments
Post a Comment