23 March 2021

Image name space removed and insert in database table

<?php

$servername = "localhost";

$username = "root";

$password = " ";

$dbname = "indra";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

  $Name = $_REQUEST['Name'] ;

  $Mobile_No = $_REQUEST['Mobile_No'] ;

  $City = $_REQUEST['City'] ;

  $Recipe_Name = $_REQUEST['Recipe_Name'] ;

  $files = $_FILES['Recipe_Data'];

  $file_upload = $_FILES['Sweets_Photo'];

  $new1 = str_replace(' ', '_', basename($_FILES['Recipe_Data']['name']));

   $file = '';

  $new1 = str_replace(' ', '_', basename($_FILES['Recipe_Data']['name']));

  $path1 ="http://jagranlive.in/indrajeet/uploads/".$new1;

  $newname1=$path1;

  $target_path = 'uploads/';

  move_uploaded_file($_FILES['Recipe_Data']['tmp_name'],$target_path.$new1);

  $new2 = str_replace(' ', '_', basename($_FILES['Sweets_Photo']['name']));

  $path2 ="http://jagranlive.in/indrajeet/uploads/".$new2;

  $newname=$path2;

  $target_path = 'uploads/';

  move_uploaded_file($_FILES['Sweets_Photo']['tmp_name'],$target_path.$new2);

 $sql = "INSERT INTO enquiry (Name, Mobile_No, City, Recipe_Name, Recipe_Data,Sweets_Photo) VALUES ('".$Name."', '".$Mobile_No."', '".$City."','".$Recipe_Name."','".$newname1."','".$newname."')";

if ($conn->query($sql) === TRUE) {

  echo "New record created successfully";

}

else {

  echo "Error: " . $sql . "<br>" . $conn->error;

}

$conn->close();

?>