This question already has an answer here:
I'm making an android application that can upload multiple image to server, to make sure that my php is working, i'm trying it on postman, but when i try it on postman the response is null
this is the reponse i get from postman
i've reading some website for tutorial of this app and write the php exactly like that but it's keep sending null on my post request
Android Upload Image using Android Upload Service
Android Upload Image From Gallery To Server Using PHP MySQL
Android Upload Image to Server Using PHP MySQL
Android Upload Image to Server Using PHP and MySQL
This is my php
<?php
//importing dbDetails file
require_once 'dbDetails.php';
//this is our upload folder
$upload_path = 'upload/';
//Getting the server ip
$server_ip = gethostbyname(gethostname());
//creating the upload url
$upload_url = 'http://'.$server_ip.'/opr57/'.$upload_path;
//response array
$response = array();
if($_SERVER['REQUEST_METHOD']=='POST'){
//checking the required parameters from the request
if(isset($_POST['nama']) and isset($_FILES['image']['foto_ktp'])){
//connecting to the database
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect...');
//getting name from the request
$id_dropping = $_POST['id_dropping'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$tr = $_POST['tr'];
$parkiran = $_POST['parkiran'];
$resort = $_POST['resort'];
$pinjaman = $_POST['pinjaman'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$ktp = $_POST['foto_ktp'];
$nasabah = $_POST['foto_nasabah'];
$status = $_POST['status'];
$ktpinfo = pathinfo($_FILES['image']['foto_ktp']);
$nasabahinfo = pathinfo($_FILES['image']['foto_nasabah']);
$extensionktp = $ktpinfo['extension'];
$extensionnasabah = $nasabahinfo['extension'];
$ktpurl = $upload_url.getFileName().'.'.$extensionktp;
$ktppath =
$upload_path.getFileName().'.'.$extensionktp;
$nasabahurl = $upload_url.getFileName().'.'.$extensionnasabah;
$nasabahpath = $upload_path.getFileName().'.'.$extensionnasabah;
//trying to save the file in the directory
try{
//saving the file
move_uploaded_file($_FILES['image']['tmp_nama'],$ktppath);
move_uploaded_file($_FILES['image']['tmp_nama'],$nasabahpath);
try{
//saving the file
move_uploaded_file($_FILES['image']['tmp_name'],$file_path);
move_uploaded_file($_FILES['image2']['tmp_name'],$file_path2);
$stmt = $conn->prepare("INSERT INTO dropping(id_dropping, nama, alamat, tr, parkiran, resort , pinjaman ,latitude,longitude,foto_ktp,foto_nasabah status) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("ssssssssssss", $id_dropping,$name,$alamat,$tr,$parkiran,$resort,$pinjaman,$latitude,$longitude,$file_url,$file_url2,$status);
//$sql = "INSERT INTO `opr57`.`dropping` (`id_dropping`,`nama`,`alamat`,`tr`,`parkiran`,`resort`,`pinjaman`,`latitude`,`longitude`,`foto_ktp`,`foto_nasabah`,`status`) VALUES ('$id_dropping', '$name', '$alamat', '$tr', '$parkiran', '$resort', '$pinjaman','$latitude', '$longitude', '$file_url', '$file_url2', '$status');";
//adding the path and name to database
//if(mysqli_query($con,$sql))
if($stmt->execute()){
//filling response array with values
$response['error'] = false;
$response['url'] = $file_url;
$response['url2'] = $file_url2;
$response['name'] = $name;
}
else{
$error = $mysqli->errno . ' ' . $mysqli->error;
echo $error; // 1054 Unknown column 'foo' in 'field list'
//if some error occurred
}}catch(Exception $e){
$response['error']=true;
$response['message']=$e->getMessage();
}
//displaying the response
echo json_encode($response);
//closing the connection
mysqli_close($con);
}else{
$response['error']=true;
$response['message']='Please choose a file';
}
}
i expect the output to be like this {"error":false,"url":"http:\/\/192.168.43.149\/opr57\/upload\/9.jpg","url2":"http:\/\/192.168.43.149\/opr57\/upload\/9.jpg""name":"Bayu"}
, but the actual output is like this
<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function bind_param() on bool in D:\xampp\htdocs\opr57\upload.php:63
Stack trace:
#0 {main}
thrown in
<b>D:\xampp\htdocs\opr57\upload.php</b> on line
<b>63</b>
<br />
I'm really looking forward for an answer. Thank you very much
</div>