php - App crashed when save button is clicked -


i wonder possible update image path , image in folder ?

i've been stored image path , text mysql android, , save image in directory.

enter image description here

php upload image

<?php     if( $_server['request_method']=='post' ){         if( !empty( $_post['listitems'] ) ){             $listitems = json_decode( $_post['listitems'], true );              $mysqli = new mysqli("127.0.0.1:3307", "root", "", "androiddb");             if( $mysqli->connect_errno ) echo "failed connect mysql";             $sql="insert `staff_benefit`                   ( `type`, `amount`, `description`, `image`, `ts_id` )                    values ( ?, ?, ?, ?, ? )";             if($stmt=$mysqli->prepare($sql )){                 $url="http://192.168.1.7:80/android/crud/photoupload/";                 foreach( $listitems $item ){                      $id = uniqid();                     $image_name = $id.".png";                     $save_path = 'photoupload/'.$image_name;                     $image_url = $url.$image_name;                     $bytes=file_put_contents($save_path, base64_decode($item['image']));                     if( !$bytes ){                         echo 'error saving image';                       }else{                         $stmt->bind_param('sssss',                          $item['type'],                          $item['amount'],                          $item['description'],                          $image_url,                          $item['ts_id'] );                         if( !$res=$stmt->execute()){                              echo 'query failed code: '.$stmt->errno;                         }                     }                 }              }             $mysqli->close();         }     } ?> 

in edit_staff_benefit_listview, 2 row data retrieved , loaded listview. when list clicked, intent edit_staff edit.

edit_staff_benefit_listview

 listviewedit.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> listview, view view,                                     int position, long id) {                 mclickedposition = position; // update                 long i1d = staffs.get(position).getid();                 intent intent = new intent(getactivity(), edit_staff.class);                 intent.putextra("id", i1d);                 intent.putextra("id", id);  // ts_id                 intent.putextra("mclickedposition", mclickedposition);                 startactivityforresult(intent, project_request_code);             }         }); 

edit_staff

  mclickedposition=getintent().getintextra("mclickedposition",-1);             id = getintent().getlongextra("id", 0);             idfrominfo=getintent().getstringextra("id");             toast.maketext(getapplicationcontext(), "id" + id+"fk"+idfrominfo , toast.length_long).show();             if (getintent().getextras() != null) {                 retrievedetails(id);  // retrieve data based on position in listview             }     save.setonclicklistener(new view.onclicklistener() {     // if save button clicked             @override             public void onclick(view v) {                 intent returnintent = new intent();                 claimtype = spinnertype.getselecteditem().tostring();                 description = description.gettext().tostring();                 amount = amount.gettext().tostring();                 if(mclickedposition==-1)                 {                  //add(claimtype,amount,description,photo);                 }                 else                 {                     update(claimtype,amount,description,photo);                 }              }         }); 

update function

 public void update( final string claimtype,  final string amount, final string description, final uri photo)     {            class updateimageandtext extends asynctask<void,void,string>{                progressdialog loading;                @override                protected void onpreexecute() {                    super.onpreexecute();                    loading = progressdialog.show(edit_staff.this,"updating...","wait...",false,false);                }                 @override                protected void onpostexecute(string s) {                    super.onpostexecute(s);                    loading.dismiss();                    toast.maketext(getapplicationcontext(), s, toast.length_long).show();                    try {                        intent returnintent = new intent();                        returnintent.putextra("claimtype", claimtype);                        returnintent.putextra("amount", amount);                        returnintent.putextra("description", description);                        returnintent.putextra("photo", photo);                        setresult(activity.result_ok, returnintent);                        finish();                    }catch(exception e)                    {                     }                }                 @override                protected string doinbackground(void... params) {                    hashmap<string,string> hashmap = new hashmap<>();                    hashmap.put(configs.key_id,string.valueof(id));                    hashmap.put(configs.key_type,claimtype);                    hashmap.put(configs.key_amount,amount);                    hashmap.put(configs.key_description,description);                    hashmap.put(configs.key_image,photo.tostring());                    requesthandler rh = new requesthandler();                    string s = rh.sendpostrequest(configs.url_updatede_image_text,hashmap);                    return s;                }            } 

update.php

<?php      if($_server['request_method']=='post'){         //getting values           $id = $_post['id'];         $type = $_post['type'];         $amount = $_post['amount'];         $description = $_post['description'];         $image = $_post['image'];           //importing database connection script          require_once('dbconnect.php');           $sql = "update staff_benefit                    set type = '$type', amount = '$amount', description='description', image='image'                  id = '$id'";          //updating database table          if(mysqli_query($con,$sql)){             echo ' updated successfully';         }else{              echo mysqli_error($con);             exit;         }          //closing connection          mysqli_close($con);     } ?> 

app crashed when save button clicked.is because i'm wrote wrong update. php ? thanks

logcat

01-16 19:36:51.373  22786-22786/com.example.project.myapplication e/windowmanager﹕ android.view.windowleaked: activity com.example.project.myapplication.gui.edit_staff has leaked window com.android.internal.policy.impl.phonewindow$decorview{42c71d80 v.e..... r......d 0,0-684,324} added here             @ android.view.viewrootimpl.<init>(viewrootimpl.java:467)             @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:267)             @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69)             @ android.app.dialog.show(dialog.java:289)             @ android.app.progressdialog.show(progressdialog.java:116)             @ android.app.progressdialog.show(progressdialog.java:104)             @ com.example.project.myapplication.gui.edit_staff$1updateimageandtext.onpreexecute(edit_staff.java:154)             @ android.os.asynctask.executeonexecutor(asynctask.java:587)             @ android.os.asynctask.execute(asynctask.java:535)             @ com.example.project.myapplication.gui.edit_staff.update(edit_staff.java:191)             @ com.example.project.myapplication.gui.edit_staff$1.onclick(edit_staff.java:103) 

@tony when error, means window leaking progress dialog.

this happens when don't cancel it, happened because app crashes before that.

to see real error remove progressdialog loading; sake of debugging.

also have logic issues, code should check if image has been selected or not , add hashmap.

if uri not initialized , don't check getting nullpointerexception.

you need send image encoded in base64 did in old question. uri path file on device need encoding, not inserted in table.you need reupload new image instead.

your php script should check parameters being passed. if photo did not change not updated field can have condition checking $_post['image'] if not set run update query without image column.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -