I need to update my data include some input field text and have 5 file type image

  insert-update, php

this is my database where all the data is stored:
this is my database where my all the data is stored

Whenever I want to update my either single data or either single or multiple pictures from existing record only that part would be updated other data would not be changed
this is my update form:
this is my update form

Here is my code updatecode

if(isset($_POST['Submit']))
{


// var_dump($_POST);

$var1 = rand(1111,9999);  // generate random number in $var1 variable
$var2 = rand(1111,9999);  // generate random number in $var2 variable

$var3 = $var1.$var2;  // concatenate $var1 and $var2 in $var3
$var3 = md5($var3);   // convert $var3 using md5 function and generate 32 characters hex number


$p_name=$_POST['p_name'];

$address_desc=$_POST['address_desc'];


$fnm1 = $_FILES["image1"]["name"];    // get the image name in $fnm variable
$dst1 = "./all_images/".$var3.$fnm1;  // storing image path into the {all_images} folder with 32 characters hex number and file name
$dst_db1 = "all_images/".$var3.$fnm1; // storing image path into the database with 32 characters hex number and file name

$fnm2 = $_FILES["image2"]["name"];    // get the image name in $fnm variable
$dst2 = "./all_images/".$var3.$fnm2;  // storing image path into the {all_images} folder with 32 characters hex number and file name
$dst_db2 = "all_images/".$var3.$fnm2; // storing image path into the database with 32 characters hex number and file name

$fnm3 = $_FILES["image3"]["name"];    // get the image name in $fnm variable
$dst3 = "./all_images/".$var3.$fnm3;  // storing image path into the {all_images} folder with 32 characters hex number and file name
$dst_db3= "all_images/".$var3.$fnm3; // storing image path into the database with 32 characters hex number and file name

$fnm4 = $_FILES["image4"]["name"];    // get the image name in $fnm variable
$dst4 = "./all_images/".$var3.$fnm4;  // storing image path into the {all_images} folder with 32 characters hex number and file name
$dst_db4 = "all_images/".$var3.$fnm4; // storing image path into the database with 32 characters hex number and file name

$fnm5 = $_FILES["image5"]["name"];    // get the image name in $fnm variable
$dst5 = "./all_images/".$var3.$fnm5;  // storing image path into the {all_images} folder with 32 characters hex number and file name
$dst_db5 = "all_images/".$var3.$fnm5; // storing image path into the database with 32 characters hex number and file name

move_uploaded_file($_FILES["image1"]["tmp_name"],$dst1);  // move image into the {all_images} folder with 32 characters hex number and image name
move_uploaded_file($_FILES["image2"]["tmp_name"],$dst2); 
move_uploaded_file($_FILES["image3"]["tmp_name"],$dst3); 
move_uploaded_file($_FILES["image4"]["tmp_name"],$dst4); 
move_uploaded_file($_FILES["image5"]["tmp_name"],$dst5); 

$id=$_POST['id'];
$p_name=$_POST['p_name'];
$address_desc=$_POST['address_desc'];
$rooms=$_POST['rooms'];
$bathrooms=$_POST['bathrooms'];

$bedrooms=$_POST['bedrooms'];
$parking=$_POST['parking'];

$area=$_POST['area'];

$price=$_POST['price'];
$region=$_POST['region'];
$add_content=$_POST['add_content'];
$property_type=$_POST['property_type'];
$added_on=$_POST['added_on'];

$userid=$_POST['userid'];
$statusid=$_POST['statusid'];


$query=mysqli_query($con,"update tbltest1 set id='$id' ,p_name='$p_name' , address_desc='$address_desc', image1='$dst_db1', image2='$dst_db2', image3='$dst_db3', image4='$dst_db4', image5='$dst_db5',rooms='$rooms',bathrooms='$bathrooms',bedrooms='$bedrooms',parking='$parking',area='$area', price='$price', region='$region'
,add_content='$add_content',property_type='$property_type',added_on='$added_on',userid='$userid', statusid='$statusid'
where id='$id'");

Source: Ask PHP

LEAVE A COMMENT