PHP的多个图像更新

时间:2019-02-04 19:47:25

标签: php mysqli

我正在创建PHP多图像更新页面,如果我选择了所有图像文件,而我只想更新一个和第二个图像,我的脚本将仅更新一个图像,第二个图像更新。不起作用

这是我的代码

    private void registerUser(final String phone,final String otp,final String fullname,final String email,  final String password, final String device_id )
    {

        Log.e(TAG, "otp12 " +otp11);

        String tag_string_req = "req_register";



        Map<String, String> params = new HashMap<String, String>();
        params.put("Content-Type", "application/json");



        params.put("phone",phone);
        params.put("otp",otp);
        params.put("fullname", fullname);
        params.put("email",email);


        params.put("password",password);

        params.put("device_id", device_id);

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                AppConfig.Base_Url+AppConfig.App_api+AppConfig.URL_REGISTER, new JSONObject(params),
                new Response.Listener<JSONObject>()

 {

                  @Override
                    public void onResponse(JSONObject response1) {

                Log.d(TAG, "Register Response: " + response1.toString());


                try {
                    JSONObject jObj = new JSONObject(String.valueOf(response1));
                    String response = jObj.getString("code");
                    String status =jObj.getString("status");
                    String message= jObj.getString("message");

                    Log.e(TAG, "r2222" + response);
                    Log.e(TAG, "status1: " + status);
                    Log.e(TAG,"Message"+message);
                    if (status!=null && status.equals("true")) {

                        launchAgeScreen();

                        Log.e(TAG, "123" + fullname);
                        Log.e(TAG, "status: " + status);
                        Log.e(TAG, "paswword: " + password);

                        Log.e(TAG, "response2163123: " + response);

                    }else if (status!=null && message.equals("user is already register"))
                    {
                        AlertDialog.Builder builder =new AlertDialog.Builder(RegisterActivity.this);
                        builder.setTitle("Registration Error");
                        builder.setMessage("You have already registered with FeeDeposit. Please click Okay to Login");
                        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent intent = new Intent(RegisterActivity.this,LoginActivityWithoutSharedPreference.class);
                                startActivity(intent);
                            }
                        });
                        AlertDialog alertDialog = builder.create();
                        alertDialog.show();

                    }


                    else if (status!=null && message.equals("invalid otp"))
                    {

                        AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();

                        // Setting Dialog Title
                        alertDialog.setTitle("OTP ");

                        // Setting Dialog Message
                        alertDialog.setMessage("Invalid OTP");

                        // Setting Icon to Dialog
                        //  alertDialog.setIcon(R.drawable.tick);

                        // Setting OK Button
                        alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                // Write your code here to execute after dialog closed
                                // Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                            }
                        });

                        alertDialog.show();

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    //Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                }

            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {

                if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                    AlertDialog alertDialog = new AlertDialog.Builder(RegisterActivity.this, R.style.MyDialogTheme).create();

                    // Setting Dialog Title
                    alertDialog.setTitle("Network/Connection Error");

                    // Setting Dialog Message
                    alertDialog.setMessage("Internet Connection is poor OR The Server is taking too long to respond.Please try again later.Thank you.");

                    // Setting Icon to Dialog
                    //  alertDialog.setIcon(R.drawable.tick);

                    // Setting OK Button
                    alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // Write your code here to execute after dialog closed
                            // Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                        }
                    });

                    // Showing Alert Message
                    alertDialog.show();
                   // Log.e(TAG, "Registration Error: " + error.getMessage());
                    /*Toast.makeText(context,
                            context.getString(R.string.error_network_timeout),
                            Toast.LENGTH_LONG).show();*/
                } /*else if (error instanceof AuthFailureError) {
                    //TODO
                } else if (error instanceof ServerError) {
                    //TODO
                } else if (error instanceof NetworkError) {
                    //TODO
                } else if (error instanceof ParseError) {
                    //TODO
                }
*/



            }
        }) /*{

            @Override
            protected Map<String, String> getParams() throws AuthFailureError{
                // Posting params to register url

                Map<String, String> params = new HashMap<String, String>();
                params.put("Content-Type", "application/json");



                params.put("phone",phone);
                params.put("otp",otp);
                params.put("fullname", fullname);
                params.put("email",email);


                params.put("password",password);

                params.put("device_id", device_id);




                return params;
            }

        }*/;






        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
                MY_SOCKET_TIMEOUT_MS,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
                && Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
            try {
                ProviderInstaller.installIfNeeded(getApplicationContext());
            } catch (GooglePlayServicesRepairableException e) {
                // Indicates that Google Play services is out of date, disabled, etc.
                // Prompt the user to install/update/enable Google Play services.
                GooglePlayServicesUtil.showErrorNotification(e.getConnectionStatusCode(), getApplicationContext());
                // Notify the SyncManager that a soft error occurred.
                //final SyncResult syncResult = null;
                //syncResult.stats.numIOExceptions++;

                //Toast.makeText(getApplicationContext(), "Sync", Toast.LENGTH_LONG).show();
                return;
            } catch (GooglePlayServicesNotAvailableException e) {
                // Indicates a non-recoverable error; the ProviderInstaller is not able
                // to install an up-to-date Provider.
                // Notify the SyncManager that a hard error occurred.
                //syncResult.stats.numAuthExceptions++;
               // Toast.makeText(getApplicationContext(), "Sync12", Toast.LENGTH_LONG).show();
                return;
            }

            HttpStack stack = null;
            try {
                stack = new HurlStack(null, new TLSSocketFactory());
            } catch (KeyManagementException e) {
                e.printStackTrace();
                Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
                stack = new HurlStack();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                Log.d("Your Wrapper Class", "Could not create new stack for TLS v1.2");
                stack = new HurlStack();
            }

             Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);
           // AppController.getInstance().addToRequestQueue(getApplicationContext(),stack);

            requestQueue = Volley.newRequestQueue(getApplicationContext(), stack);
        } else {

            requestQueue = Volley.newRequestQueue(getApplicationContext());
            //AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
        }

        Appcontrol.getInstance().addToRequestQueue(jsonObjReq, tag_string_req);




        // Adding request to request queue
      //
        //
        //
        //
        //
        //AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
    }

1 个答案:

答案 0 :(得分:1)

我认为您的逻辑不正确。逻辑应该是

if($_SERVER['REQUEST_METHOD'] == "POST"){
$id=$_POST['id'];
$title=$_POST['title'];
$desc1=$_POST['desc1'];
$content=$_POST['content'];
$category=$_POST['category'];
$random = substr(number_format(time() * rand(),0,'',''),0,10); 
$img= $random .$_FILES['image']['name'][0];
$image_tmp= $_FILES['image']['tmp_name'][0];
$img1= $random .$_FILES['image']['name'][1];
$image_tmp1= $_FILES['image']['tmp_name'][1];
if(move_uploaded_file($image_tmp,"images/$img")){
move_uploaded_file($image_tmp1,"images/$img1");
$stmt = $con->prepare("UPDATE products SET title=?, desc1=?, content=?,  category=?,img=?,img1=?  WHERE id=?"); 
$stmt->bind_param("sssssss", $title, $desc1, $content,  $category, $img,$img1, $id);
} else if (move_uploaded_file($image_tmp1,"images/$img1")) {
move_uploaded_file($image_tmp1,"images/$img");
$stmt = $con->prepare("UPDATE products SET title=?, desc1=?, content=?,  category=? WHERE id=?"); 
$stmt->bind_param("sssss", $title, $desc1, $content,  $category, $id);
}
if($stmt->execute()){
header('location:edit-source.php');
}else{
echo "Failed to update product<br/>";
}
}
?>

或者,我建议将其包装在一个函数中以使其可重用。