How to send path of the image to DB using PHP?

Here is a code which will help to fetch the image path and send to the DB using PHP.

HTML code

<input type="file" name="file" value="">

 PHP code

<?php
include "db.php";// Database conection
$sourcePath = $_FILES['file']['tmp_name'];// Storing source path of the file in a variable
$file1 = $_FILES["file"]["name"];
$filePath = "upload/" . $file1;
$targetPath = "upload/".$_FILES['file']['name']; // Target path where file is to be stored
move_uploaded_file($sourcePath,$targetPath) ; 
//echo ($email_id);
$q = mysqli_query($con, "insert into tablename (image) value($filePath);
If ($q){
echo( "correct");
                
 } else {
  echo( "SOME ERROR OCCURED");
  }
Posted on by