php - Input data from android to database in mysql -
i have code:
<?php include('konek.php'); $entid=$_post['entid']; $entsender=$_post['entsender']; $enttitle=$_post['enttitle']; $entdate=$_post['entdate']; $entsagrade=$_post['entsagrade']; $entreason=$_post['entreason']; $entproblem=$_post['entproblem']; $enttime=$_post['enttime']; if($row_num != 0) { $ins=mysql_query("insert tblentry(entid,entsender,enttitle,enttime,entsagrade,entreason,entproblem) values('$entid','$entsender','$enttitle',curtime(),'$entsagrade','$entreason','$entproblem')"); echo "added"; } else { echo "added."; } ?>
my problem is, when input data in android simulator, not adding. problem in code?
and here code in android:
public class addentry extends activity { button buttonsave; edittext ent1, ent2, ent3, ent4, ent5, ent6 ; httppost httppost; httpresponse response; httpclient httpclient; list<namevaluepair> namevaluepairs; progressdialog dialog = null; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.addentry); buttonsave = (button)findviewbyid(r.id.save); ent1 = (edittext)findviewbyid(r.id.entsender); ent2 = (edittext)findviewbyid(r.id.entdate); ent3 = (edittext)findviewbyid(r.id.enttitle); ent4 = (edittext)findviewbyid(r.id.entsagrade); ent5 = (edittext)findviewbyid(r.id.entreason); ent6 = (edittext)findviewbyid(r.id.entproblem); buttonsave.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { dialog = progressdialog.show(addentry.this, "", "adding entry. . .", true); new thread(new runnable() { public void run() { insertentry(); } }).start(); } }); } void insertentry(){ try{ httpclient=new defaulthttpclient(); httppost= new httppost("http://10.0.2.2/smcfi/insertentry.php"); // make sure url correct. //add data namevaluepairs = new arraylist<namevaluepair>(6); // use same variable name posting i.e android side variable name , php side variable name should similar, namevaluepairs.add(new basicnamevaluepair("ensender",ent1.gettext().tostring().trim())); // $edittext_value = $_post['edittext_value']; namevaluepairs.add(new basicnamevaluepair("entdate",ent2.gettext().tostring().trim())); namevaluepairs.add(new basicnamevaluepair("enttitle",ent3.gettext().tostring().trim())); namevaluepairs.add(new basicnamevaluepair("entsagrade",ent4.gettext().tostring().trim())); namevaluepairs.add(new basicnamevaluepair("entreason",ent5.gettext().tostring().trim())); namevaluepairs.add(new basicnamevaluepair("entproblem",ent6.gettext().tostring().trim())); httppost.setentity(new urlencodedformentity(namevaluepairs)); //execute http post request response=httpclient.execute(httppost); // edited james coderzheaven.. <span id="il_ad10" class="il_ad">from here</span>.... responsehandler<string> responsehandler = new basicresponsehandler(); final string response = httpclient.execute(httppost, responsehandler); system.out.println("response : " + response); runonuithread(new runnable() { public void run() { // tv.settext("response php : " + response); dialog.dismiss(); } }); if(response.equalsignorecase("added")){ runonuithread(new runnable() { public void run() { toast.maketext(addentry.this,"successfully added.", toast.length_short).show(); intent intent = new intent(addentry.this, entry.class); addentry.this.startactivity(intent); addentry.this.finish(); } }); }else{ showalert(); } }catch(exception e){ dialog.dismiss(); system.out.println("exception : " + e.getmessage()); } } public void showalert(){ addentry.this.runonuithread(new runnable() { public void run() { alertdialog.builder builder = new alertdialog.builder(addentry.this); builder.settitle("error"); builder.setmessage("not added.") .setcancelable(false) .setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }); alertdialog alert = builder.create(); alert.show(); } }); } @override public void onbackpressed() { intent intent = new intent(addentry.this, mainact.class); addentry.this.startactivity(intent); addentry.this.finish(); }
}
i dont know error. not adding. inputted data not adding database.
found typo -
$ins=mysql_query("insert tblentry (entid,entsender,enttitle,enttime,entsagrade,entreason,entproblem) values ('$entid','$entsender','$enttitle',curtime(),'$entsagrade','$entreason','$entproblem'));" ^=== should inside round bracket
change -
$ins=mysql_query("insert tblentry (entid,entsender,enttitle,enttime,entsagrade,entreason,entproblem) values ('$entid','$entsender','$enttitle',curtime(),'$entsagrade','$entreason','$entproblem')");
Comments
Post a Comment