Android code does not insert into mysql database using PHP -
i trying insert data android code mysql database using php code not anything.
register.php:
<?php // array json response $response = array(); // check required fields if (isset($_post['n'])) { $name = $_post['n']; $address = $_post['add']; //$age = $_post['age']; $phone = $_post['phone']; $email = $_post['e']; $bloodgroup = $_post['bloodgroup']; // include db connect class require_once __dir__ . '/db_connect.php'; // connecting db $db = new db_connect(); // mysql inserting new row $result = mysql_query("insert bloodtb(name,address,phone,email,bloodgroup) values ('$name','$address','$phone','$email','$bloodgroup')"); // check if row inserted or not if ($result) { // inserted database $response["success"] = 1; $response["message"] = "product created."; // echoing json response echo json_encode($response); } else { // failed insert row $response["success"] = 0; $response["message"] = "oops! error occurred."; // echoing json response echo json_encode($response); } } else { // required field missing $response["success"] = 0; $response["message"] = "required field(s) missing"; // echoing json response echo json_encode($response); } ?>
register.java:
public class register extends activity { edittext name,address,bg,ph,email,age; button register; private progressdialog pdialog; int flag=0; jsonparser jsonparser = new jsonparser(); private static string url = "http://192.168.43.41/phpfiles/register.php"; private static final string tag_success = "success"; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.register); name=(edittext)findviewbyid(r.id.etname); // age=(edittext)findviewbyid(r.id.etage); address=(edittext)findviewbyid(r.id.etadd); bg=(edittext)findviewbyid(r.id.etbg); email=(edittext)findviewbyid(r.id.etemail); ph=(edittext)findviewbyid(r.id.etphone); register=(button)findviewbyid(r.id.btnreg); register.setonclicklistener(new view.onclicklistener() { public void onclick(view view){ new thread(new runnable() { @override public void run() { new loginaccess().execute(); } }); } }); } class loginaccess extends asynctask<string, string, string> { protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(register.this); pdialog.setmessage("registering.."); pdialog.setindeterminate(false); pdialog.setcancelable(true); pdialog.show(); } @override protected string doinbackground(string... arg0) { list<namevaluepair> params = new arraylist<namevaluepair>(); string n=name.gettext().tostring(); //string a=age.gettext().tostring(); string add=address.gettext().tostring(); string e=email.gettext().tostring(); string phone=ph.gettext().tostring(); string bloodgroup=bg.gettext().tostring(); params.add(new basicnamevaluepair("n", n)); // params.add(new basicnamevaluepair("age", a)); params.add(new basicnamevaluepair("add",add)); params.add(new basicnamevaluepair("phone",phone)); params.add(new basicnamevaluepair("e", e)); params.add(new basicnamevaluepair("bloodgroup",bloodgroup)); jsonobject json = jsonparser.makehttprequest(url,"post", params); log.d("create response", json.tostring()); try { int success = json.getint(tag_success); if (success == 1) { flag=0; //intent = new intent(getapplicationcontext(),search.class); /*i.putextra("mobile_number",number); i.putextra("password",pwd);*/ //startactivity(i); finish(); } else { // failed sign in flag=1; } } catch (jsonexception ex) { ex.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { pdialog.dismiss(); if(flag==1) toast.maketext(register.this,"please enter correct informations", toast.length_long).show(); } } }
there no error in log cat still nothing being inserted database..please help.
you not starting thread code not executed @ all
new thread(new runnable() { @override public void run() { new loginaccess().execute(); } }).start();
asynctask executed on different thread below code should execute task
new loginaccess().execute();
Comments
Post a Comment