update mysql by php in android using json -
i tried make activity changes mysql database
i made web server code
<?php //error_reporting(0); require_once('db_config.php'); if($conn){ $sql = "update order_detail set order_status ='completed', order_id = $order_id"; if(mysqli_query($conn,$sql)){ $response['result'] =true; $response['message'] = 'update order successfully'; }else{ $response['result'] =false; $response['message'] = 'unable take order'; } }else{ $response['result'] =false; $response['message'] = 'some fields missing'; } }else{ $response['result'] =false; $response['message'] = 'unable connect database'; } echo json_encode($response); mysqli_close($conn); ?>
and connected android activity request commend, dont have idea why not working
private void completeorder() { // todo auto-generated method stub
if (utils.checkconnection(this)) new ordertask().execute(); else toast.maketext(this, "no connection found", toast.length_short).show(); } public class ordertask extends asynctask<void, void, boolean> { private progressdialog pd; private boolean result = false; private stringbuilder item_ids,item_names; @override protected void onpreexecute() { // todo auto-generated method stub super.onpreexecute(); pd = new progressdialog(singlecontactactivity.this); pd.setmessage("processing order,please wait"); pd.setprogressstyle(progressdialog.style_spinner); pd.setcancelable(false); pd.show(); } @override protected boolean doinbackground(void... params) { // todo auto-generated method stub httpclient client = new defaulthttpclient(); httppost post = new httppost(utils.ws_update_order); list<namevaluepair> mparams = new arraylist<namevaluepair>(); mparams.add(new basicnamevaluepair("order_status","completed")); mparams.add(new basicnamevaluepair("order_id",order_id.tostring())); try { post.setentity(new urlencodedformentity(mparams)); httpresponse response = client.execute(post); string res = entityutils.tostring(response.getentity()); log.d("order preview", res); jsonobject jsonobj = new jsonobject(res); result = jsonobj.getboolean("result"); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } return result; } @override protected void onpostexecute(boolean res) { // todo auto-generated method stub super.onpostexecute(res); if (pd != null) pd.dismiss(); if (res) { toast.maketext(singlecontactactivity.this, "order submitted successfully", toast.length_short) .show(); intent intent = new intent(singlecontactactivity.this, categorylist.class); intent.addflags(intent.flag_activity_clear_top); startactivity(intent); } else { toast.maketext(singlecontactactivity.this, "unable process order", toast.length_short) .show(); } } }
you may need use mysqli_affected_rows()
in query result because mysqli_query($conn,$sql)
return query result , go if condition
. have count number of affected row.
also found syntax error in last else condition
it may be
<?php //error_reporting(0); require_once('db_config.php'); if ($conn) { $sql = "update `order_detail` set `order_status` ='completed', `order_id` = $order_id"; $result = mysqli_query($conn, $sql); if (mysqli_affected_rows($result) > 0) { $response['result'] = true; $response['message'] = 'update order successfully'; } else { $response['result'] = false; $response['message'] = 'unable take order'; } } else { $response['result'] = false; $response['message'] = 'some fields missing'; }
Comments
Post a Comment