how to upload the path of an image to Mysql database with android using php files

971

i want to add an image's path with android to mysql database using a php file. i added the path with a php file to the database but i failed to connect the android app to the php file si i can put the path of the image from android to mysql database can anyone tell me the rignt procedure for doing it ? this is my php file :

       <?php 
     define('hostname','localhost');
     define('user', 'root');
     define('password', '');
     define('databasename', 'image');




     $connect=mysqli_connect(hostname,user,password,databasename);
     ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file_img" />
<input type="submit" name="btn_upload" value="Upload">  
</form>

<?php
if(isset($_POST['btn_upload']))
{
    $filetmp = $_FILES["file_img"]["tmp_name"];
    $filename = $_FILES["file_img"]["name"];
    $filetype = $_FILES["file_img"]["type"];
    $filepath = "photo/".$filename;

    move_uploaded_file($filetmp,$filepath);

    $sql = "INSERT INTO img (img_name,img_path,img_type) VALUES ('$filename','$filepath','$filetype')";
    $result = mysqli_query($connect,$sql);
}
?>

</body>
</html>

People are also looking for solutions to the problem: ubuntu - php mkdir creates a folder with lock icon

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.