Volley post只对图像和文本一起工作到mysql db

I am posting 4 text and 1 image to mysql db using the Volley library. The code works only once after that i am getting only empty response when i try to post and no data is seen in the sql db as well. Added all the necessary permissions in the Android manifest as well but not able to fond what is wrong with this code.

JAVA:

public class Main extends AppCompatActivity implements View.OnClickListener {

RadioButton radioType;
RadioGroup radioGroup;
EditText FoodName,FoodLocation,ShopName;
TextView Camera,Gallery,Post;
ImageView imageView;
private Bitmap bitmap;

private int PICK_IMAGE_REQUEST = 1;
private String UPLOAD_URL ="http://xyz.ttt.com/upload.php";

private String KEY_IMAGE = "image";
private String KEY_NAME = "FoodName";
private String KEY_LOCATION = "FoodLocation";
private String KEY_SHOP = "ShopName";
private String KEY_TYPE = "Type";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    radioGroup = (RadioGroup)findViewById(R.id.RadioGroup);
    FoodName = (EditText)findViewById(R.id.FoodName);
    FoodLocation = (EditText)findViewById(R.id.FoodLocation);
    ShopName = (EditText)findViewById(R.id.ShopName);
    Camera = (TextView)findViewById(R.id.Camera);
    Gallery = (TextView)findViewById(R.id.Gallery);
    Post = (TextView)findViewById(R.id.Post);
    imageView=(ImageView)findViewById(R.id.image);
    Camera.setOnClickListener(this);
    Gallery.setOnClickListener(this);
    Post.setOnClickListener(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    if(v == Gallery){
        showFileChooser();
    }
    if(v == Post){
        uploadImage();
    }
}

private void showFileChooser() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri filePath = data.getData();
        try {
            //Getting the Bitmap from Gallery
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
            //Setting the Bitmap to ImageView
            imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

private void uploadImage(){
    //Showing the progress dialog
    final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    //Disimissing the progress dialog
                    loading.dismiss();
                    //Showing toast message of the response
                    Toast.makeText(Main.this, s, Toast.LENGTH_LONG).show();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    //Dismissing the progress dialog
                    loading.dismiss();

                    //Showing toast
                    Toast.makeText(Main.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            //Converting Bitmap to String
            String image = getStringImage(bitmap);

            //Getting Image Name
            String FName = FoodName.getText().toString().trim();

            String FLocation = FoodLocation.getText().toString().trim();

            String SName = ShopName.getText().toString().trim();

            int selectedId = radioGroup.getCheckedRadioButtonId();
            radioType = (RadioButton)findViewById(selectedId);
            String rType = radioType.getText().toString().trim();


            //Creating parameters
            Map<String, String> params = new Hashtable<String, String>();

            //Adding parameters
           params.put(KEY_IMAGE, image);
            params.put(KEY_NAME, FName);
            params.put(KEY_LOCATION, FLocation);
            params.put(KEY_SHOP, SName);
            params.put(KEY_TYPE, rType);


           //returning parameters
            return params;
        }
    };

    //Creating a Request Queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);
} }

PHP:

if($_SERVER['REQUEST_METHOD']=='POST'){

    $image = $_POST['image'];
            $FoodName = $_POST['FoodName'];
            $FoodLocation = $_POST['FoodLocation'];
    $ShopName = $_POST['ShopName'];
            $Type = $_POST['Type'];

    require_once('dbConnect.php');

    $sql ="SELECT id FROM foodstore ORDER BY id ASC";

    $res = mysqli_query($con,$sql);

    $id = 0;

    while($row = mysqli_fetch_array($res)){
            $id = $row['id'];
    }

    $path = "images/$id.png";

    $actualpath = "http://xyz.ttt.com/$path";

    $sql = "INSERT INTO foodstore (image,FoodName,FoodLocation,ShopName,Type) VALUES ('$actualpath','$FoodName','$FoodLocation','$ShopName','$Type')";

    if(mysqli_query($con,$sql)){
        file_put_contents($path,base64_decode($image));
        echo "Successfully Uploaded";
    }

    mysqli_close($con);
}else{
    echo "Error";
}

What is wrong with the above code?

douqin1932
douqin1932 WAMP和XAMPP都是适用于您计算机的最佳Web开发平台。它们允许您在开发期间测试计算机上的Web应用程序,包括MySql数据库查询。您可以设置本地MySql数据库。我在上线之前用它来测试我的网络应用程序。
4 年多之前 回复
duanqiang6501
duanqiang6501 别担心。我会在早上解释它并测试你的代码。基本上,这两个程序允许您在发布之前测试本地网络上的服务器端代码。
4 年多之前 回复
dongluobei9359
dongluobei9359 是的它是空洞的回应。我不知道WAMP或XAMPP。
4 年多之前 回复
dtnrsmi824877
dtnrsmi824877 似乎没有显示成功或错误响应。您是否尝试过使用WAMP或XAMPP进行测试?
4 年多之前 回复
dongzhuanlei0768
dongzhuanlei0768 D/Volleyï•[6720]BasicNetwork.logSlowRequests:请求的HTTP响应=<[]xyz.ttt.com/upload.php0x460c6660NORMAL1>[lifetime=3031],[size=0],[rc=200],[retryCount=0]和W/IInputConnectionWrapperï•showStatusIcon在非活动的InputConnection上
4 年多之前 回复
duandiao3961
duandiao3961 如果您在尝试再次发布时将视图设置为详细信息,是否在AndroidStudiologcat中获得任何网络响应?
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问