如何在androidstudio中使用volley和php上传图像和文本视图数据?

fv2wmkja  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(351)

我已经创建了一个应用程序上传图像和文本,使用截击和php。这里是upload.php

  1. include_once "koneksi.php";
  2. class emp{}
  3. $image = $_POST['image'];
  4. $name = $_POST['name'];
  5. //ini kode yang saya tambah yaitu item
  6. $item = $_POST['item']
  7. if (empty($name)) {
  8. $response = new emp();
  9. $response->success = 0;
  10. $response->message = "Please dont empty Name.";
  11. die(json_encode($response));
  12. } else {
  13. $random = random_word(20);
  14. $path = "images/".$random.".png";
  15. // sesuiakan ip address laptop/pc atau URL server
  16. $actualpath = "http://192.168.43.137/android/upload_image/$path";
  17. // saya tambah variabel item
  18. $query = mysqli_query($con, "INSERT INTO volley_upload (photo,name,item) VALUES ($actualpath','$name','$item')");
  19. if ($query){
  20. file_put_contents($path,base64_decode($image));
  21. $response = new emp();
  22. $response->success = 1;
  23. $response->message = "Successfully Uploaded";
  24. die(json_encode($response));
  25. } else{
  26. $response = new emp();
  27. $response->success = 0;
  28. $response->message = "Error Upload image";
  29. die(json_encode($response));
  30. }
  31. }
  32. // fungsi random string pada gambar untuk menghindari nama file yang sama
  33. function random_word($id = 20){
  34. $pool = '1234567890abcdefghijkmnpqrstuvwxyz';
  35. $word = '';
  36. for ($i = 0; $i < $id; $i++){
  37. $word .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  38. }
  39. return $word;
  40. }
  41. mysqli_close($con);

?>
同样对于它的.xml部分,我使用fab作为图像上传按钮和2 textview ie edititem和edittext。我还将imageview添加到要上传的图像中。在我用xml和java添加textview edititem项之前,应用程序运行得很好,但是在我决定再添加一个textview来上载(因此总共有2个textview)之后,数据没有成功地发送到数据库,而之前上载了1个图像和1个textview描述,但我的目标是上传1张图片和2个文本视图描述,但上传1张图片和2个文本视图失败(edittext,edititem)
我该怎么解决这个问题?我想上传1个图片和2个文本视图(edittext,edititem)
mainactivity.java=https://drive.google.com/open?id=1uxkxgmpropojikflkxxgmxyrmgxbo3se 活动\u main.xml=https://drive.google.com/open?id=1xpso2z_s0cv078ubuizx1jjpfmg9k9_2
这是logcat

lokaqttq

lokaqttq1#

根据logcat日志,php部分是不正确的。

  1. $item = $_POST['item']; // <--- You should put a comma at the end.

相关问题