dubking India
dubking India

Reputation: 35

Undefined index image in PHP, I know this is duplication but I have tried many solution but none worked

I want to make an application in android where user uploads photo and that uploads will be inserted in my MySQL database using PHP

but my PHP script generates an error that

Undefined index image in PHP

following is my PHP files-

"Constants.php"

<?php
$db_name="mydb";
$local_username="root";
$local_password="";
$server_name="localhost";
$conn= 
mysqli_connect($server_name,$local_username,$local_password,$db_name);
if($conn)
{
echo "Connection successful";
}
else  
{
echo "Connectionj failed";
}

?>

"imageUploadScript.php"

<?php
require "Constants.php"; 
 if($_SERVER['REQUEST_METHOD'] == 'POST')
 {
  $DefaultId = 0;
  $image = $_POST['image'];
 $mobile = $_POST['mobile'];
// if(isset($_POST['image']))
//{ 
 $ImagePath = "imageUploads/$mobile.jpg";
 $ServerURL = "yourPath/$ImagePath";
 $InsertSQL = "INSERT INTO info (img) values('$ServerURL') where 
mobile=$mobile";
 if(mysqli_query($conn, $InsertSQL)){
 file_put_contents($ImagePath,base64_decode($ImageData));
 echo "Your Image Has Been Uploaded.";
mysqli_close($conn);
 }
 else{
 echo "Please Try Again";
 }
//}
}
?>

any help from your side will be appreciated

Upvotes: 0

Views: 91

Answers (1)

Prakash Pazhanisamy
Prakash Pazhanisamy

Reputation: 983

For uploading an image, you need to use

$_FILES['image']

instead of

$_POST['image']

Upvotes: 1

Related Questions