Hi
I'm currently creating a property website and it allows users to submit upto 7 images/property.
Currently on clicking the 'submit' button to Add A Propety my code checks for image size, file type and then moves the file from a tmp location to images/propertyimages file.
All the images from all users go to the same directory.
Therefore if one user has an image called kitchen.jpg and then another user submits an image called kitchen.jpg, the first one gets overwritten and both users will have the same image on their property.

I have a a few ideas, but not sure which one would be the most practical and whether there is a better, simpler solution available (bearing in mind my coding is still on an uphill learning curve)

1. On 'Submit' prefix or add a number to the image and each subsequent image submitted gets the next sequential number.

2. Prefix the User ID to the image (the user has to be logged in to Add A Property and therefore the ID is stored in the S_SESSION) and then get the 'Submit'to check for image name uniqueness using something like this for each of the 7 images:

if (!empty($image_main_name)  
{
      // Make sure name isn't already in use
      $query = "SELECT * FROM property_details WHERE image = '$image_main_name'";
........
}

This then at least keeps the issue within each of the users own properties.

3. Prefix each image name with the property ID. This would ensure that each image was unique across all users and no need to prompt users to change an image name before submitting etc etc.

However currently the site is based on the Property ID being created after the Property has been submitted with the column in the database automatically incrementing the property ID's as each one is submitted.

I do not know how to go about creating a unique property ID on clicking 'Submit'so that the the property ID is created upfront in order to prefix to the image name.

I'm also not sure how to append even the user ID to each image name.

I'm also not sure whether any of these ideas are the best way forward?

I've attached the code used to far to check the image size/type etc and submit to the required directly. Only the image name gets submitted to the database.

Any help in this would be great and much appreciated as I'm at a real sticking point now and the site is pretty much finished apart from this :-)

Many thanks in advance liz

<?php require_once('Connections/xxxxxxxx_localhost.php'); 
      require_once('myaccess/appvars.php');

// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxxxx", "xxxxxxxxx");

function checkfile($image_name,$type,$size,$tmp_name,$error)
{
	
	$output ='start';

	if (!empty($image_name)) 
	   {
      if (
	  (($type == 'image/gif') || ($type == 'image/jpg') || ($type == 'image/pjpeg') || ($type == 'image/png') || ($type == 'image/jpeg'))
	  && (($size > 0) && ($size <= GW_MAXFILESIZE))
		  && ($error == '0'))
	  {
        // Move the files to the target upload folder
          $target = GW_UPLOADPATH . $image_name;
		  if (move_uploaded_file($tmp_name , $target) ) {$output = 'success';} else {$output = 'load error'; }
	  } 
	  else { $output='error'; }
	   }
	  else { $output='success'; }

	return $output;
}


  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST - I have removed the non image fields.
    $ID = ($_POST['ID']);
	$screenpath = "images/propertyimages/";
	$image_main_name = mysqli_real_escape_string($dbc, trim($_FILES['image_main']['name']));
	$image_kitchen_name = mysqli_real_escape_string($dbc, trim($_FILES['image_kitchen']['name']));
	$image_bed_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bed']['name']));
	$image_bath_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bath']['name']));
	$image_living_name = mysqli_real_escape_string($dbc, trim($_FILES['image_living']['name']));
	$image_dining_name = mysqli_real_escape_string($dbc, trim($_FILES['image_dining']['name']));
	$image_garden_name = mysqli_real_escape_string($dbc, trim($_FILES['image_garden']['name']));
	
	
	$image_main_check = checkfile($_FILES['image_main']['name'],$_FILES['image_main']['type'],$_FILES['image_main']['size'],$_FILES['image_main']['tmp_name'],$_FILES['image_main']['error']) ;
	$image_kitchen_check = checkfile($_FILES['image_kitchen']['name'],$_FILES['image_kitchen']['type'],$_FILES['image_kitchen']['size'],$_FILES['image_kitchen']['tmp_name'],$_FILES['image_kitchen']['error']) ;
	$image_bed_check = checkfile($_FILES['image_bed']['name'],$_FILES['image_bed']['type'],$_FILES['image_bed']['size'],$_FILES['image_bed']['tmp_name'],$_FILES['image_bed']['error']) ;
	$image_bath_check = checkfile($_FILES['image_bath']['name'],$_FILES['image_bath']['type'],$_FILES['image_bath']['size'],$_FILES['image_bath']['tmp_name'],$_FILES['image_bath']['error']) ;
	$image_living_check = checkfile($_FILES['image_living']['name'],$_FILES['image_living']['type'],$_FILES['image_living']['size'],$_FILES['image_living']['tmp_name'],$_FILES['image_living']['error']) ;
	$image_dining_check = checkfile($_FILES['image_dining']['name'],$_FILES['image_dining']['type'],$_FILES['image_dining']['size'],$_FILES['image_dining']['tmp_name'],$_FILES['image_dining']['error']) ;
	$image_garden_check = checkfile($_FILES['image_garden']['name'],$_FILES['image_garden']['type'],$_FILES['image_garden']['size'],$_FILES['image_garden']['tmp_name'],$_FILES['image_garden']['error']) ;


   
	  if ($image_main_check == 'success' && $image_kitchen_check == 'success' && $image_bed_check == 'success' && $image_bath_check == 'success' && $image_living_check == 'success' && $image_dining_check == 'success' && $image_garden_check == 'success') 
		  {
	
   
// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxx", "xxxxxxxx");	

 $query = "INSERT INTO property_details
VALUES (0, NOW(), '$ID', '$add_owner', '$add_block', '$add_road', '$add_house', '$add_unit', '$add_area', '$add_postcode', '$add_zone', '$prop_cat', '$prop_hot', 'Active', '$prop_contact', '$prop_type', '$prop_saletype', '$prop_desc', '$prop_tenure', '$prop_bedroom', '$prop_bathroom', '$prop_price', '$prop_garage', '$prop_park', '$prop_pool', '$prop_garden', '$prop_alarm', '$prop_appliance', '$screenpath', '$image_main_name', '$image_kitchen_name', '$image_bed_name', '$image_bath_name', '$image_living_name', '$image_dining_name', '$image_garden_name')";
                      
  mysqli_query($dbc, $query);
// Confirm success with the user - I've taken out this bit as it just adds unecessary length...

            // Clear the image data to clear the form
            $image_main = "";
			$image_kitchen = "";
			$image_bed = "";
			$image_bath = "";
			$image_living = "";
			$image_dining = "";
			$image_garden = "";
			
			
            mysqli_close($dbc);
			exit();
          }
      elseif (($image_main_check == 'error' ) || ($image_kitchen_check == 'error' ) || ($image_bed_check == 'error' ) || ($image_bath_check == 'error' ) || ($image_living_check == 'error' ) || ($image_dining_check == 'error' ) || ($image_garden_check == 'error' ))	   {
		  
	  echo '<p class="maintextactive">All the images must be a GIF, JPG, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size. Please return to the form and re-select your images.</p>';
      }
      elseif (($image_main_check == 'load error' )  || ($image_kitchen_check == 'load error' ) || ($image_bed_check == 'load error' ) || ($image_bath_check == 'load error' ) || ($image_living_check == 'load error' ) || ($image_dining_check == 'load error' ) || ($image_garden_check == 'load error' )) {
	 
	  echo '<p class="maintextactive">The files did not load successfully. Please try again</p>';      }
	 
	  else {echo '<p class="maintextactive">Someting else has gone wrong</p>';	  }

      // Try to delete the temporary screen shot image file
      @unlink($_FILES['image_main']['tmp_name']) && ($_FILES['image_kitchen']['tmp_name']) && ($_FILES['image_bed']['tmp_name']) && ($_FILES['image_bath']['tmp_name']) && ($_FILES['image_living']['tmp_name']) && ($_FILES['image_dining']['tmp_name']) && ($_FILES['image_garden']['tmp_name']);
 
     }
    else { echo '<p class="maintextbold">Please enter all of the information to add to your property.</p>';  }
	
	

?>

Generate random number using rand() and add it to the prefix of file name.. No need to check for uniqueness if you do like this....

I have a 4th idea.

When the image is moved from the tmp directory to images/propertyimages - could we just create a new folder under propertyimages for each submitted property? Then would have to ensure that when the user edits that image it stays in that folder?

Hi Thanks for getting back to me.

Would this generate a new number each time? Even if several thousand properties ended up being submitted to the site, each with the full 7 images?

cheers liz

Yes it generate new number for every time. Adding random number to the file name is easiest way to avoid duplicate names....

Hi Thanks

Where would I put this rand() in my current code checks?

change your line 20 with

$target = GW_UPLOADPATH.rand().$image_name;

I've dealt with this before. Although it would nearly NEVER happen, you need to be sure that no duplicate image names *could* possibly exist - because if it could happen, it will happen, and someone is going to have the wrong image in their property listing, etc no big deal, but let's take care of it anyway. So here is what I would do.

First I would insert entry into mysql without the file names, pull mysql insert id, upload files with user ID + unix time stamp + rand number + original file name, save file names in mysql entry.

I've never used 'mysqli', I use mysql. But I figure they are basically the same thing?

<?php

require_once('Connections/xxxxxxxx_localhost.php'); 
require_once('myaccess/appvars.php');
require_once('mysql_config.php'); // Connect to DB


/*Random Characters*/
function randchars($length = 8,$lowercase = true,$uppercase = true,$number = true,$misc = false){
/*By John Minton - http://iluvjohn.com/ */
for($i=1;$i<=$length;$i++){
if($lowercase == true){$rand[] = rand(97,122);}
if($uppercase == true){$rand[] = rand(65,90);}
if($number == true){$rand[] = rand(48,57);}
if($misc == true){$rand[] = rand(33,46);}
$count = count($rand)-1;
$rand_case = rand(1,$count);
$string .= chr($rand[$rand_case]);
unset($rand); // reset rand
}
return($string);
}

function checkfile($image_name,$type,$size,$tmp_name,$error)
{
	
	$output ='start';

	if (!empty($image_name)) 
	   {
      if (
	  (($type == 'image/gif') || ($type == 'image/jpg') || ($type == 'image/pjpeg') || ($type == 'image/png') || ($type == 'image/jpeg'))
	  && (($size > 0) && ($size <= GW_MAXFILESIZE))
		  && ($error == '0'))
	  {
        // Move the files to the target upload folder
        
        
        
        function new_image_name($image_name){
        $rand = randchars();
        $new_img_name = $_SESSION['userid']."_".date("U")."_$rand_".$image_name
        if(file_exists($new_img_name))
        {
        new_image_name($image_name);
        }else{
        return($new_img_name);
        }
        }
        
        //Create a random filename, and double check that the file does not exist, loop until unique filename.
        $image_name = new_image_name($image_name);
        
          $target = GW_UPLOADPATH . $image_name;
		  if (move_uploaded_file($tmp_name , $target) ) {$output = 'success';} else {$output = 'load error'; }
	  } 
	  else { $output='error'; }
	   }
	  else { $output='success'; }

	return array('output' => $output, 'image_name' => $image_name);
}


if(isset($_POST['submit'])) {
// Grab the profile data from the POST - I have removed the non image fields.
  $ID = ($_POST['ID']);
	$screenpath = "images/propertyimages/";
	$image_main_name = mysqli_real_escape_string($dbc, trim($_FILES['image_main']['name']));
	$image_kitchen_name = mysqli_real_escape_string($dbc, trim($_FILES['image_kitchen']['name']));
	$image_bed_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bed']['name']));
	$image_bath_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bath']['name']));
	$image_living_name = mysqli_real_escape_string($dbc, trim($_FILES['image_living']['name']));
	$image_dining_name = mysqli_real_escape_string($dbc, trim($_FILES['image_dining']['name']));
	$image_garden_name = mysqli_real_escape_string($dbc, trim($_FILES['image_garden']['name']));
	
	
	$image_main_check = checkfile($_FILES['image_main']['name'],$_FILES['image_main']['type'],$_FILES['image_main']['size'],$_FILES['image_main']['tmp_name'],$_FILES['image_main']['error']) ;
	$image_kitchen_check = checkfile($_FILES['image_kitchen']['name'],$_FILES['image_kitchen']['type'],$_FILES['image_kitchen']['size'],$_FILES['image_kitchen']['tmp_name'],$_FILES['image_kitchen']['error']) ;
	$image_bed_check = checkfile($_FILES['image_bed']['name'],$_FILES['image_bed']['type'],$_FILES['image_bed']['size'],$_FILES['image_bed']['tmp_name'],$_FILES['image_bed']['error']) ;
	$image_bath_check = checkfile($_FILES['image_bath']['name'],$_FILES['image_bath']['type'],$_FILES['image_bath']['size'],$_FILES['image_bath']['tmp_name'],$_FILES['image_bath']['error']) ;
	$image_living_check = checkfile($_FILES['image_living']['name'],$_FILES['image_living']['type'],$_FILES['image_living']['size'],$_FILES['image_living']['tmp_name'],$_FILES['image_living']['error']) ;
	$image_dining_check = checkfile($_FILES['image_dining']['name'],$_FILES['image_dining']['type'],$_FILES['image_dining']['size'],$_FILES['image_dining']['tmp_name'],$_FILES['image_dining']['error']) ;
	$image_garden_check = checkfile($_FILES['image_garden']['name'],$_FILES['image_garden']['type'],$_FILES['image_garden']['size'],$_FILES['image_garden']['tmp_name'],$_FILES['image_garden']['error']) ;


if($image_main_check[0] == 'success' && $image_kitchen_check[0] == 'success' && $image_bed_check[0] == 'success' && $image_bath_check[0] == 'success' && $image_living_check[0] == 'success' && $image_dining_check[0] == 'success' && $image_garden_check[0] == 'success') 
{

$query = "INSERT INTO property_details VALUES (0, NOW(), '$ID', '$add_owner', '$add_block', '$add_road', '$add_house', '$add_unit', '$add_area', '$add_postcode', '$add_zone', '$prop_cat', '$prop_hot', 'Active', '$prop_contact', '$prop_type', '$prop_saletype', '$prop_desc', '$prop_tenure', '$prop_bedroom', '$prop_bathroom', '$prop_price', '$prop_garage', '$prop_park', '$prop_pool', '$prop_garden', '$prop_alarm', '$prop_appliance', '$screenpath','','','','','','','')";
                      
mysqli_query($dbc, $query);

$mysql_insert_id = mysql_insert_id(); // Get the primary key of last mysql transaction

/* I am assuming some column names, and the primary key column name - might need correction. */
$query = "UPDATE property_details SET image_main_name='".$image_main_name[1]."', image_kitchen_name='".$image_kitchen_name[1]."', image_bed_name='".$image_bed_name[1]."', image_bath_name='".$image_bath_name[1]."', image_living_name='".$image_living_name[1]."', image_dining_name='".$image_dining_name[1]."', image_garden_name='".$image_garden_name[1]."' WHERE ID = '$mysql_insert_id'");
$ud = mysqli_query($dbc, $query);

// Confirm success with the user - I've taken out this bit as it just adds unecessary length...


      // Clear the image data to clear the form
      unset($image_main,$image_kitchen,$image_bed,$image_bath,$image_living,$image_dining,$image_garden);
			
			exit();
          }
      elseif (($image_main_check[0] == 'error' ) || ($image_kitchen_check[0] == 'error' ) || ($image_bed_check[0] == 'error' ) || ($image_bath_check[0] == 'error' ) || ($image_living_check[0] == 'error' ) || ($image_dining_check[0] == 'error' ) || ($image_garden_check[0] == 'error' ))	   {
		  
	  echo '<p class="maintextactive">All the images must be a GIF, JPG, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size. Please return to the form and re-select your images.</p>';
      }
      elseif (($image_main_check[0] == 'load error' )  || ($image_kitchen_check[0] == 'load error' ) || ($image_bed_check[0] == 'load error' ) || ($image_bath_check[0] == 'load error' ) || ($image_living_check[0] == 'load error' ) || ($image_dining_check[0] == 'load error' ) || ($image_garden_check[0] == 'load error' )) {
	 
	  echo '<p class="maintextactive">The files did not load successfully. Please try again</p>';      }
	 
	  else {echo '<p class="maintextactive">Someting else has gone wrong</p>';	  }

      // Try to delete the temporary screen shot image file
      @unlink($_FILES['image_main']['tmp_name']) && ($_FILES['image_kitchen']['tmp_name']) && ($_FILES['image_bed']['tmp_name']) && ($_FILES['image_bath']['tmp_name']) && ($_FILES['image_living']['tmp_name']) && ($_FILES['image_dining']['tmp_name']) && ($_FILES['image_garden']['tmp_name']);
 
     }
    else { echo '<p class="maintextbold">Please enter all of the information to add to your property.</p>';  }
	
	
mysqli_close($dbc);
?>

I want to suggest also, Instead of dealing with all the images with their own variable names (which causes you to have to handle them individually), Try modifying the file upload form to place the images into an array, and then you can simply loop through them with ease. It will also cut down on the amount of code you have too.
Mess around with this:

<form action="temp.php" method="post" enctype="multipart/form-data">
Image 1: <input type="file" name="images[]" /><br />
Image 2: <input type="file" name="images[]" /><br />
Image 3: <input type="file" name="images[]" /><br />
Submit: <input type="submit" name="submit" value="Go Go Upload!" />
</form>

<?php
echo "<pre>";

print_r($_FILES);


?>

~John

Hi Thanks guys this has all been really really helpful! And works. What I've actually done (but I really like the latest suggestion but just need to get a working model completed first) is:

$target = GW_UPLOADPATH.time() . '_' . mt_rand().$image_name;

Together with the unix generated time stamp and large rand numbers I feel should be ok.

However I'm now having an issue with the fact that the whole newly generated image name is not showing up in the database column, so although the images names are getting uploaded into the server directory - they are not showing up in the actual website... any ideas?

Can you provide a little more information? This is kind of one of those things that is easier to look at than to explain I know, but the first thing that comes to mind is to check the file names in the folder, and file names in the database....double check html path to images is proper, etc. Direct access the images in the folder and make sure they are being saved properly and in working order.

Hi Thanks for getting back to me.
Yes the problem is caused because the name in the datbase is now different from the name in the file directory.
My $image_name just contain the actual image name that is uploaded form the users pc..ie.kitchen.jpg

it is because $image_main_name which is what is inserted into the database, only contains whatever is checked in the $image_main_check variable.
Therefore before I inserted time() . '_' . rand() into the $target only the image_name is put into the database. This is successful as it matched what was in the file directory.

Now the names do not match. But Im not sure how to include the whole new path into the $image_main_name variable?

Does this help? sorry will try and rethink it more clearly..

It is

Ok, when you do the move_uploaded_file function, you specify the tmp_name and the new file name (the file name with unix time stamp, id, + origianl file name, etc). You do this function in a funntion called check, right? So since move_uploaded_file moves the file AND renames it, the check function returns an array instead of just an error code / result which contains first the error code you originally had, and then the new file name which has been successfully moved and renamed. I might have to just get a copy of your whole code in order to really understand....would that be possible? Then I can just run a local copy and do it that way. What we are trying to do is actually really simple, just messy because there is a lot of code.

I'm going to bed now, I'll check back in the morning.

Hi Thanks
The entire code is very long as there is a lot more in the page then just the form..
I've attached the above code with the form only. The form has several fields which are populated dynamically though...so obviously data wont'be able to be added and so forth....

many thanks for the help though..much appreciated. I'll try and work through it also :-)

<?php require_once('Connections/dreamsin_localhost.php'); 
      require_once('myaccess/appvars.php');

// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxxxx", "xxxxxxxxx", "xxxxxxxxx");

function checkfile($image_name,$type,$size,$tmp_name,$error)
{
	
	$output ='start';

	if (!empty($image_name)) 
	   {
      if (
	  (($type == 'image/gif') || ($type == 'image/jpg') || ($type == 'image/pjpeg') || ($type == 'image/png') || ($type == 'image/jpeg'))
	  && (($size > 0) && ($size <= GW_MAXFILESIZE))
		  && ($error == '0'))
	  {
        // Move the files to the target upload folder
          $target = GW_UPLOADPATH . time() . '_' . mt_rand() . $image_name;
		  if (move_uploaded_file($tmp_name , $target) ) {$output = 'success';} else {$output = 'load error'; }
	  } 
	  else { $output='error'; }
	   }
	  else { $output='success'; }

	return $output;
}


  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST
    $ID = ($_POST['ID']);
	$add_owner = mysqli_real_escape_string($dbc, trim($_POST['add_owner']));
	$add_block = mysqli_real_escape_string($dbc, trim($_POST['add_block']));
	$add_road = mysqli_real_escape_string($dbc, trim($_POST['add_road']));
	$add_house = mysqli_real_escape_string($dbc, trim($_POST['add_house']));
	$add_unit = mysqli_real_escape_string($dbc, trim($_POST['add_unit']));
	$add_area = mysqli_real_escape_string($dbc, trim($_POST['add_area']));
	$add_postcode = mysqli_real_escape_string($dbc, trim($_POST['add_postcode']));
	$add_zone = mysqli_real_escape_string($dbc, trim($_POST['add_zone']));
	$prop_cat = mysqli_real_escape_string($dbc, trim($_POST['prop_cat']));
	$prop_hot = mysqli_real_escape_string($dbc, trim($_POST['prop_hot']));
	$prop_sold = mysqli_real_escape_string($dbc, trim($_POST['prop_sold']));
	$prop_contact = mysqli_real_escape_string($dbc, trim($_POST['prop_contact']));
	$prop_type = mysqli_real_escape_string($dbc, trim($_POST['prop_type']));
	if ($prop_type == 'Private Apartments') { $prop_saletype = ($_POST['prop_saletype1']); } 
	else if ($prop_type == 'Landed Property') { $prop_saletype = ($_POST['prop_saletype2']);}
	else if ($prop_type == 'Hdb Flat') { $prop_saletype = ($_POST['prop_saletype3']);}
	else if ($prop_type == 'Commercial') { $prop_saletype = ($_POST['prop_saletype4']);}
	else if ($prop_type == 'Hudc Apartments') { $prop_saletype = ($_POST['prop_saletype5']);}
	$prop_desc = mysqli_real_escape_string($dbc, trim($_POST['prop_desc']));
	$prop_tenure = mysqli_real_escape_string($dbc, trim($_POST['prop_tenure']));
	$prop_bedroom = mysqli_real_escape_string($dbc, trim($_POST['prop_bedroom']));
	$prop_bathroom = mysqli_real_escape_string($dbc, trim($_POST['prop_bathroom']));
	$prop_price = mysqli_real_escape_string($dbc, trim($_POST['prop_price']));
	$prop_garage = mysqli_real_escape_string($dbc, trim($_POST['prop_garage']));
	$prop_park = mysqli_real_escape_string($dbc, trim($_POST['prop_park']));
	$prop_pool = mysqli_real_escape_string($dbc, trim($_POST['prop_pool']));
	$prop_garden = mysqli_real_escape_string($dbc, trim($_POST['prop_garden']));
	$prop_alarm = mysqli_real_escape_string($dbc, trim($_POST['prop_alarm']));
	$prop_appliance = mysqli_real_escape_string($dbc, trim($_POST['prop_appliance']));
	$screenpath = "images/propertyimages/";
	$image_main_name = mysqli_real_escape_string($dbc, trim($_FILES['image_main']['name']));
	$image_kitchen_name = mysqli_real_escape_string($dbc, trim($_FILES['image_kitchen']['name']));
	$image_bed_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bed']['name']));
	$image_bath_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bath']['name']));
	$image_living_name = mysqli_real_escape_string($dbc, trim($_FILES['image_living']['name']));
	$image_dining_name = mysqli_real_escape_string($dbc, trim($_FILES['image_dining']['name']));
	$image_garden_name = mysqli_real_escape_string($dbc, trim($_FILES['image_garden']['name']));
	
	
	$image_main_check = checkfile($_FILES['image_main']['name'],$_FILES['image_main']['type'],$_FILES['image_main']['size'],$_FILES['image_main']['tmp_name'],$_FILES['image_main']['error']) ;
	$image_kitchen_check = checkfile($_FILES['image_kitchen']['name'],$_FILES['image_kitchen']['type'],$_FILES['image_kitchen']['size'],$_FILES['image_kitchen']['tmp_name'],$_FILES['image_kitchen']['error']) ;
	$image_bed_check = checkfile($_FILES['image_bed']['name'],$_FILES['image_bed']['type'],$_FILES['image_bed']['size'],$_FILES['image_bed']['tmp_name'],$_FILES['image_bed']['error']) ;
	$image_bath_check = checkfile($_FILES['image_bath']['name'],$_FILES['image_bath']['type'],$_FILES['image_bath']['size'],$_FILES['image_bath']['tmp_name'],$_FILES['image_bath']['error']) ;
	$image_living_check = checkfile($_FILES['image_living']['name'],$_FILES['image_living']['type'],$_FILES['image_living']['size'],$_FILES['image_living']['tmp_name'],$_FILES['image_living']['error']) ;
	$image_dining_check = checkfile($_FILES['image_dining']['name'],$_FILES['image_dining']['type'],$_FILES['image_dining']['size'],$_FILES['image_dining']['tmp_name'],$_FILES['image_dining']['error']) ;
	$image_garden_check = checkfile($_FILES['image_garden']['name'],$_FILES['image_garden']['type'],$_FILES['image_garden']['size'],$_FILES['image_garden']['tmp_name'],$_FILES['image_garden']['error']) ;


   
	  if ($image_main_check == 'success' && $image_kitchen_check == 'success' && $image_bed_check == 'success' && $image_bath_check == 'success' && $image_living_check == 'success' && $image_dining_check == 'success' && $image_garden_check == 'success') 
		  {
	
   
// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxxx", "xxxxxxxxx", "xxxxxxxx");	

 $query = "INSERT INTO property_details
VALUES (0, NOW(), '$ID', '$add_owner', '$add_block', '$add_road', '$add_house', '$add_unit', '$add_area', '$add_postcode', '$add_zone', '$prop_cat', '$prop_hot', 'Active', '$prop_contact', '$prop_type', '$prop_saletype', '$prop_desc', '$prop_tenure', '$prop_bedroom', '$prop_bathroom', '$prop_price', '$prop_garage', '$prop_park', '$prop_pool', '$prop_garden', '$prop_alarm', '$prop_appliance', '$screenpath', '$image_main_name', '$image_kitchen_name', '$image_bed_name', '$image_bath_name', '$image_living_name', '$image_dining_name', '$image_garden_name')";
                      
  mysqli_query($dbc, $query);
// Confirm success with the user
		echo '<p class="maintextbold">Thanks for Listing your Property! Please view your listing below. <br />You may <a href="../view_property_record.php">view and edit</a> your listing at anytime.</p>';
   	    ?>
                <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr class="maintext">
                    <td width="109">Registered User ID: </td>
                    <td width="144"><span class="maintextbold"><?php echo number_format($_POST[ID],0,".",","); ?></span></td>
                    <td width="170">Property Owner: </td>
                    <td width="177" ><span class="maintextbold"><?php echo "$add_owner"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Block No.: </td>
                    <td><span class="maintextbold"><?php echo "$add_block"?></span></td>
                    <td>Road Name: </td>
                    <td><span class="maintextbold"><?php echo "$add_road"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>House Name: </td>
                    <td><span class="maintextbold"><?php echo "$add_house"?></span></td>
                    <td>Unit No.: </td>
                    <td><span class="maintextbold"><?php echo "$add_unit"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Area: </td>
                    <td><span class="maintextbold"><?php echo "$add_area"?></span></td>
                    <td>Postcode: </td>
                    <td><span class="maintextbold"><?php echo "$add_postcode"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Zone No.: </td>
                    <td><span class="maintextbold"><?php echo "$add_zone"?></span></td>
                    <td>Category:</td>
                    <td><span class="maintextbold"><?php echo "$prop_cat"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Property Contact: </td>
                    <td><span class="maintextbold"><?php echo "$prop_contact"?></span></td>
                    <td>Property Type: </td>
                    <td><span class="maintextbold"><?php echo "$prop_type"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Property sub-type: </td>
                    <td><span class="maintextbold"><?php echo "$prop_saletype"?></span></td>
                    <td>Tenure: </td>
                    <td><span class="maintextbold"><?php echo "$prop_tenure"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Bedrooms: </td>
                    <td><span class="maintextbold"><?php echo "$prop_bedroom"?></span></td>
                    <td>Bathrooms: </td>
                    <td><span class="maintextbold"><?php echo "$prop_bathroom"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Price:</td>
                    <td><span class="maintextbold">$<?php echo number_format($prop_price,0,".",",")?></span></td>
                    <td>Garage: </td>
                    <td><span class="maintextbold"><?php echo "$prop_garage"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Off Street Parking: </td>
                    <td><span class="maintextbold"><?php echo "$prop_park"?></span></td>
                    <td>Swimming Pool: </td>
                    <td><span class="maintextbold"><?php echo "$prop_pool"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>Garden: </td>
                    <td><span class="maintextbold"><?php echo "$prop_garden"?></span></td>
                    <td>Alarm System: </td>
                    <td><span class="maintextbold"><?php echo "$prop_alarm"?></span></td>
                    </tr>
                  <tr class="maintext">
                    <td>White Goods: </td>
                    <td><span class="maintextbold"><?php echo "$prop_appliance" ?></span></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    </tr>
                  </table>
                <table width="500" border="0" align="center">
                  <tr class="maintext">
                    <td height="29" colspan="8">Property Description:<br /></td>
                    </tr>
                  <tr class="maintextbold">
                    <td colspan="8"><?php echo "$prop_desc"?></td>
                    </tr>
  </table>
                <table width="500" border="0" align="center" cellpadding="1" cellspacing="1">
                  <tr>
                    <td width="242" height="100" align="center" valign="middle"><?php  echo '<img src="' . GW_UPLOADPATH . $image_main_name . '" alt="Front of House" width="70" height="55"/></p>';?></td>
                    <td width="242" height="100" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_kitchen_name . '" alt="Kitchen" width="70" height="55"/></p>'; ?></td>
                    <td width="241" height="100" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_bed_name . '" alt="Bedroom" width="70" height="55"/></p>'; ?></td>
                    <td width="241" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_bath_name . '" alt="Bathroom" width="70" height="55"/></p>'; ?></td>
                    <td width="241" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_living_name . '" alt="Living Room" width="70" height="55"/></p>'; ?></td>
                    <td width="241" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_dining_name . '" alt="Dining Room" width="70" height="55"/></p>'; ?></td>
                    <td width="241" align="center" valign="middle"><?php echo '<img src="' . GW_UPLOADPATH . $image_garden_name . '" alt="Garden" width="70" height="55"/></p>'; ?></td>
                    </tr>
                </table>
                
             
                <?php

            // Clear the image data to clear the form
            $image_main = "";
			$image_kitchen = "";
			$image_bed = "";
			$image_bath = "";
			$image_living = "";
			$image_dining = "";
			$image_garden = "";
			
			
            mysqli_close($dbc);
			exit();
          }
      elseif (($image_main_check == 'error' ) || ($image_kitchen_check == 'error' ) || ($image_bed_check == 'error' ) || ($image_bath_check == 'error' ) || ($image_living_check == 'error' ) || ($image_dining_check == 'error' ) || ($image_garden_check == 'error' ))	   {
		  
	  echo '<p class="maintextactive">All the images must be a GIF, JPG, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size. Please return to the form and re-select your images.</p>';
      }
      elseif (($image_main_check == 'load error' )  || ($image_kitchen_check == 'load error' ) || ($image_bed_check == 'load error' ) || ($image_bath_check == 'load error' ) || ($image_living_check == 'load error' ) || ($image_dining_check == 'load error' ) || ($image_garden_check == 'load error' )) {
	 
	  echo '<p class="maintextactive">The files did not load successfully. Please try again</p>';      }
	 
	  else {echo '<p class="maintextactive">Someting else has gone wrong</p>';	  }

      // Try to delete the temporary screen shot image file
      @unlink($_FILES['image_main']['tmp_name']) && ($_FILES['image_kitchen']['tmp_name']) && ($_FILES['image_bed']['tmp_name']) && ($_FILES['image_bath']['tmp_name']) && ($_FILES['image_living']['tmp_name']) && ($_FILES['image_dining']['tmp_name']) && ($_FILES['image_garden']['tmp_name']);
 
     }
    else { echo '<p class="maintextbold">Please enter all of the information to add to your property.</p>';  }
	
	

?>
                <br />
               <table width="490"border="0" align="center" class="maintext">
                <tr>
                <td width="490" height="230">
                      <form action="add_property_record.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
                        <fieldset>
                    <legend class="maintextbold">Please Enter Details of Your Property (<span class="redtext">*</span> are mandatory fields)</legend>
                          <table width="490" align="center">
                            <tr valign="baseline">
                              <td ><table align="center">
                                <tr valign="baseline">
                                  <td width="162" align="right" valign="baseline" nowrap="nowrap">User ID</td>
                                  <td colspan="3" align="left">
                                   <input name="ID" type="text" id="ID" value="<?php echo number_format($row_rs_id['ID'],0,".",","); ?>" size="25" readonly="readonly" />
                                    (This is your Registered User ID)</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Contact_name:</td>
                                  <td colspan="3" align="left"><input name="add_owner" type="text" id="add_owner" value="<?php if (isset($_POST[add_owner])) echo $_POST['add_owner'] ?>" size="40" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Contact No:</td>
                                  <td colspan="3" align="left"><input name="prop_contact" type="text" id="prop_contact" value="<?php if (isset($_POST[prop_contact])) echo $_POST['prop_contact'] ?>"size="40" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Block No:</td>
                                  <td colspan="3" align="left"><input name="add_block" type="text" id="add_block" value="<?php if (isset($_POST[add_block])) echo $_POST['add_block'] ?>"size="40" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Road Name:</td>
                                  <td colspan="3" align="left"><input name="add_road" type="text" id="add_road" value="<?php if (isset($_POST[add_road])) echo $_POST['add_road'] ?>" size="40" maxlength="100" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">House Name:</td>
                                  <td colspan="3" align="left"><input name="add_house" type="text" id="add_house" value="<?php if (isset($_POST[add_house])) echo $_POST['add_house'] ?>" size="40" maxlength="100" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Unit No:</td>
                                  <td colspan="3" align="left"><input name="add_unit" type="text" id="add_unit" value="<?php if (isset($_POST[add_unit])) echo $_POST['add_unit'] ?>" size="40" maxlength="100" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Local Area</td>
                                  <td colspan="3" align="left">                                    <input name="add_area" type="text" id="add_area" value="<?php if (isset($_POST[add_area])) echo $_POST['add_area'] ?>" size="40" maxlength="100" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Postcode</td>
                                  <td colspan="3" align="left"><label for="add_postcode">
                                    <input name="add_postcode" type="text" id="add_postcode" value="<?php if (isset($_POST[add_postcode])) echo $_POST['add_postcode'] ?>" size="40" maxlength="100" />
                                    </label></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>District/Zone</td>
                                  <td colspan="3" align="left">                                    <select name="add_zone" id="add_zone2">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_rs_districts['district_zone']?>"><?php echo $row_rs_districts['district_zone']?></option>
                                      <?php
} while ($row_rs_districts = mysql_fetch_assoc($rs_districts));
  $rows = mysql_num_rows($rs_districts);
  if($rows > 0) {
      mysql_data_seek($rs_districts, 0);
	  $row_rs_districts = mysql_fetch_assoc($rs_districts);
  }
?>
                                    </select>
                                    (From 01-29)</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Property Category</td>
                                  <td colspan="3" align="left">                                    <select name="prop_cat" id="prop_cat">
                                      <option value="Sell">Sell</option>
                                      <option value="Rent">Rent</option>
                                    </select>
                                    <input name="prop_hot" type="hidden" id="prop_hot" value="LEAVE BLANK" size="32" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td class="maintextbold" >Basic Property Details</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right"><span class="redtext">*</span>Property Type:</td>
                                  <td colspan="3" align="left">                                    <select name="prop_type" onchange="display(this,'Private Apartments','Landed Property', 'Hdb Flat', 'Commercial', 'Hudc Apartments');">
                                      <option selected="selected">Please Select</option>
                                      <option value="Private Apartments">Private Apartments</option>
                                      <option value="Landed Property">Landed Property</option>
                                      <option value="Hdb Flat">Hdb Flat</option>
                                      <option value="Commercial">Commercial </option>
                                      <option value="Hudc Apartments">Hudc Apartments </option>
                                      <option value="invisible">Invisible</option>
                                    </select></td>
                                  </tr>
                                <tbody id="Private Apartments" style="display: none;">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right"><span class="redtext">*</span>Sale Type:</td>
                                    <td colspan="3" align="left"><select name="prop_saletype1" id="prop_saletype1">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_prop_apartment['prop_saletype']?>"><?php echo $row_prop_apartment['prop_saletype']?></option>
                                      <?php
} while ($row_prop_apartment = mysql_fetch_assoc($prop_apartment));
  $rows = mysql_num_rows($prop_apartment);
  if($rows > 0) {
      mysql_data_seek($prop_apartment, 0);
	  $row_prop_apartment = mysql_fetch_assoc($prop_apartment);
  }
?>
                                      </select></td>
                                    </tr>
                                  </tbody>
                                <tbody id="Landed Property" style="display: none;">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">&nbsp;</td>
                                    <td colspan="3" align="left"><select name="prop_saletype2" id="prop_saletype2">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_prop_landed['prop_saletype']?>"><?php echo $row_prop_landed['prop_saletype']?></option>
                                      <?php
} while ($row_prop_landed = mysql_fetch_assoc($prop_landed));
  $rows = mysql_num_rows($prop_landed);
  if($rows > 0) {
      mysql_data_seek($prop_landed, 0);
	  $row_prop_landed = mysql_fetch_assoc($prop_landed);
  }
?>
                                      </select></td>
                                    </tr>
                                  </tbody>
                                <tbody id="Hdb Flat" style="display: none;">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">&nbsp;</td>
                                    <td colspan="3" align="left"><select name="prop_saletype3" id="prop_saletype3">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_prop_hdb['prop_saletype']?>"><?php echo $row_prop_hdb['prop_saletype']?></option>
                                      <?php
} while ($row_prop_hdb = mysql_fetch_assoc($prop_hdb));
  $rows = mysql_num_rows($prop_hdb);
  if($rows > 0) {
      mysql_data_seek($prop_hdb, 0);
	  $row_prop_hdb = mysql_fetch_assoc($prop_hdb);
  }
?>
                                      </select></td>
                                    </tr>
                                  </tbody>
                                <tbody id="Commercial" style="display: none;">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">&nbsp;</td>
                                    <td colspan="3" align="left"><select name="prop_saletype4" id="prop_saletype4">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_prop_commercial['prop_saletype']?>"><?php echo $row_prop_commercial['prop_saletype']?></option>
                                      <?php
} while ($row_prop_commercial = mysql_fetch_assoc($prop_commercial));
  $rows = mysql_num_rows($prop_commercial);
  if($rows > 0) {
      mysql_data_seek($prop_commercial, 0);
	  $row_prop_commercial = mysql_fetch_assoc($prop_commercial);
  }
?>
                                      </select></td>
                                    </tr>
                                  </tbody>
                                <tbody id="Hudc Apartments" style="display: none;">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">&nbsp;</td>
                                    <td colspan="3" align="left"><select name="prop_saletype5" id="prop_saletype5">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_prop_hudc['prop_saletype']?>"><?php echo $row_prop_hudc['prop_saletype']?></option>
                                      <?php
} while ($row_prop_hudc = mysql_fetch_assoc($prop_hudc));
  $rows = mysql_num_rows($prop_hudc);
  if($rows > 0) {
      mysql_data_seek($prop_hudc, 0);
	  $row_prop_hudc = mysql_fetch_assoc($prop_hudc);
  }
?>
                                      </select></td>
                                    </tr>
                                  </tbody>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">&nbsp;</td>
                                  <td colspan="3" align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right"><span class="redtext">*</span>Property Description:</td>
                                  <td colspan="3" align="left">                                    <textarea name="prop_desc" id="prop_desc" cols="40" rows="8"><?php echo $prop_desc; ?></textarea></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Tenure:</td>
                                  <td colspan="3" align="left">                                    <select name="prop_tenure" id="prop_tenure">
                                      <?php
do {  
?>
                                      <option value="<?php echo $row_rs_tenure['prop_tenure']?>"><?php echo $row_rs_tenure['prop_tenure']?></option>
                                      <?php
} while ($row_rs_tenure = mysql_fetch_assoc($rs_tenure));
  $rows = mysql_num_rows($rs_tenure);
  if($rows > 0) {
      mysql_data_seek($rs_tenure, 0);
	  $row_rs_tenure = mysql_fetch_assoc($rs_tenure);
  }
?>
                                    </select></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Bedrooms:</td>
                                  <td colspan="3" align="left">                                    <select name="prop_bedroom" id="prop_bedroom">
                                      <option value="<?php echo $_POST['prop_bedroom']; ?>" selected="selected"><?php echo $_POST['prop_bedroom']; ?></option>
                                      <option value="1" selected="selected">1</option>
                                      <option value="2">2</option>
                                      <option value="3">3</option>
                                      <option value="4">4</option>
                                      <option value="5+">5+</option>
                                    </select></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Bathrooms</td>
                                  <td colspan="3" align="left">                                    <select name="prop_bathroom" id="prop_bathroom">
                                      <option value="<?php echo $_POST['prop_bathroom']; ?>" selected="selected"><?php echo $_POST['prop_bathroom']; ?></option>
                                      <option value="1" selected="selected">1</option>
                                      <option value="2">2</option>
                                      <option value="3">3</option>
                                      <option value="4">4</option>
                                      <option value="5+">5+</option>
                                    </select></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap"><span class="redtext">*</span>Price</td>
                                  <td colspan="3" align="left">                                    <input name="prop_price" type="text" id="prop_price" value="<?php if (isset($_POST['prop_price'])) echo $_POST['prop_price'] ?>" size="25" maxlength="100" />
                                    (no punctuation)</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td colspan="4" align="left" nowrap="nowrap"><legend class="maintextbold">Extra Features (Please check any that apply)</legend></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Garage:</td>
                                  <td width="200" align="left"><input name="prop_garage" type="checkbox" id="prop_garage" value="Y" />                                    </td>
                                  <td width="50" align="left">&nbsp;</td>
                                  <td width="50" align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Off Road Parking:</td>
                                  <td align="left"><input name="prop_park" type="checkbox" id="prop_park" value="Y" />                                    </td>
                                  <td align="left">&nbsp;</td>
                                  <td align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Swimming Pool:</td>
                                  <td align="left"><input name="prop_pool" type="checkbox" id="prop_pool" value="Y" />                                    </td>
                                  <td align="left">&nbsp;</td>
                                  <td align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Garden:</td>
                                  <td align="left"><input name="prop_garden" type="checkbox" id="prop_garden" value="Y" />                                    </td>
                                  <td align="left">&nbsp;</td>
                                  <td align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td height="22" align="right" valign="baseline" nowrap="nowrap">Alarm System</td>
                                  <td align="left"><input name="prop_alarm" type="checkbox" id="prop_alarm" value="Y" />                                    </td>
                                  <td align="left">&nbsp;</td>
                                  <td align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="right" valign="baseline" nowrap="nowrap">Integrated Appliances:</td>
                                  <td align="left"><input name="prop_appliance" type="checkbox" id="prop_appliance" value="Y" />                                    </td>
                                  <td align="left">&nbsp;</td>
                                  <td align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td align="left" nowrap="nowrap">&nbsp;</td>
                                  <td align="left" nowrap="nowrap">&nbsp;</td>
                                  <td align="left" nowrap="nowrap">&nbsp;</td>
                                  <td align="left" nowrap="nowrap">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td colspan="4" align="left" nowrap="nowrap"><legend class="maintextbold">Please Select Property Images (Please make sure your images are no larger than 32kb)</legend></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">&nbsp;</td>
                                  <td colspan="3" align="left">&nbsp;</td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Main Image</td>
                                  <td colspan="3" align="left"><input type="file" id="image_main" name="image_main" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Kitchen</td>
                                  <td colspan="3" align="left"><input type="file" id="image_kitchen" name="image_kitchen" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Bedroom</td>
                                  <td colspan="3" align="left"><input type="file" name="image_bed" id="image_bed" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Bathroom</td>
                                  <td colspan="3" align="left"><input type="file" name="image_bath" id="image_bath" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Living Room</td>
                                  <td colspan="3" align="left"><input type="file" name="image_living" id="image_living" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Dining Room</td>
                                  <td colspan="3" align="left"><input type="file" name="image_dining" id="image_dining" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td nowrap="nowrap" align="right">Garden/Yard</td>
                                  <td colspan="3" align="left"><input type="file" name="image_garden" id="image_garden" /></td>
                                  </tr>
                                <tr valign="baseline">
                                  <td colspan="4" align="center" nowrap="nowrap"><input name="submit" type="submit" id="submit" onclick="MM_validateForm('add_owner','','R','prop_contact','','RisNum','add_road','','R','add_area','','R','add_postcode','','R','prop_price','','RisNum','prop_desc','','R');return document.MM_returnValue" value="Submit Your Property" /></td>
                                  </tr>
                                </table></td>
                              </tr>
                            </table>
                          <p></p>
                          <p>&nbsp;</p>
                          </fieldset>
                        </form>
                      
                      </td>
                    </tr>
            </table>

Hi All
The problem has now been resolved: Many thanks for all your help. It has been very useful and much appreciated.

Here is the new code. I've added the function createfilename and then called that above the checkfile for each image

So after the function each image check will now have the following:

$image_main_name = createfilename($_SESSION[ID],$_FILES['image_main']['name']);
	$image_main_check = checkfile($image_main_name,$_FILES['image_main']['type'],$_FILES['image_main']['size'],$_FILES['image_main']['tmp_name'],$_FILES['image_main']['error']) ;

The whole code is attached as below:

<?php require_once('Connections/dreamsin_localhost.php'); 
      require_once('myaccess/appvars.php');

// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxxx", "xxxxxxxx", "xxxxxxx");

function createfilename($ID,$image_name)
{

	if (!empty($image_name)) 
	{
	$output = number_format($ID,0,".",",") . '_' . time() . '_' . mt_rand() .$image_name;
	return $output;
	}
	else
	{
	$output = "";
	}
}

function checkfile($image_name,$type,$size,$tmp_name,$error)
{
	
	$output ='start';

	if (!empty($image_name)) 
	   {
      if (
	  (($type == 'image/gif') || ($type == 'image/jpg') || ($type == 'image/pjpeg') || ($type == 'image/png') || ($type == 'image/jpeg'))
	  && (($size > 0) && ($size <= GW_MAXFILESIZE))
		  && ($error == '0'))
	  {
        // Move the files to the target upload folder
          $target = GW_UPLOADPATH . $image_name;
		  if (move_uploaded_file($tmp_name , $target) ) {$output = 'success';} else {$output = 'load error'; }
	  } 
	  else { $output='error'; }
	   }
	  else { $output='success'; }

	return $output;
}



  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST - removed all fields other than image fields
   	$screenpath = "images/propertyimages/";
	$image_main_name = mysqli_real_escape_string($dbc, trim($_FILES['image_main']['name']));
	$image_kitchen_name = mysqli_real_escape_string($dbc, trim($_FILES['image_kitchen']['name']));
	$image_bed_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bed']['name']));
	$image_bath_name = mysqli_real_escape_string($dbc, trim($_FILES['image_bath']['name']));
	$image_living_name = mysqli_real_escape_string($dbc, trim($_FILES['image_living']['name']));
	$image_dining_name = mysqli_real_escape_string($dbc, trim($_FILES['image_dining']['name']));
	$image_garden_name = mysqli_real_escape_string($dbc, trim($_FILES['image_garden']['name']));
	
	$image_main_name = createfilename($_SESSION[ID],$_FILES['image_main']['name']);
	$image_main_check = checkfile($image_main_name,$_FILES['image_main']['type'],$_FILES['image_main']['size'],$_FILES['image_main']['tmp_name'],$_FILES['image_main']['error']) ;
	$image_kitchen_name = createfilename($_SESSION[ID],$_FILES['image_kitchen']['name']);
	$image_Kitchen_check = checkfile($image_main_name,$_FILES['image_kitchen']['type'],$_FILES['image_kitchen']['size'],$_FILES['image_kitchen']['tmp_name'],$_FILES['image_kitchen']['error']) ;
	$image_bed_check = checkfile($_FILES['image_bed']['name'],$_FILES['image_bed']['type'],$_FILES['image_bed']['size'],$_FILES['image_bed']['tmp_name'],$_FILES['image_bed']['error']) ;
	$image_bath_check = checkfile($_FILES['image_bath']['name'],$_FILES['image_bath']['type'],$_FILES['image_bath']['size'],$_FILES['image_bath']['tmp_name'],$_FILES['image_bath']['error']) ;
	$image_living_check = checkfile($_FILES['image_living']['name'],$_FILES['image_living']['type'],$_FILES['image_living']['size'],$_FILES['image_living']['tmp_name'],$_FILES['image_living']['error']) ;
	$image_dining_check = checkfile($_FILES['image_dining']['name'],$_FILES['image_dining']['type'],$_FILES['image_dining']['size'],$_FILES['image_dining']['tmp_name'],$_FILES['image_dining']['error']) ;
	$image_garden_check = checkfile($_FILES['image_garden']['name'],$_FILES['image_garden']['type'],$_FILES['image_garden']['size'],$_FILES['image_garden']['tmp_name'],$_FILES['image_garden']['error']) ;


   
	  if ($image_main_check == 'success' && $image_kitchen_check == 'success' && $image_bed_check == 'success' && $image_bath_check == 'success' && $image_living_check == 'success' && $image_dining_check == 'success' && $image_garden_check == 'success') 
		  {
	
   
// Connect to the database
  $dbc = mysqli_connect("localhost", "xxxxxxxxx", "xxxxxxxxx", "xxxxxxxxx");	

 $query = "INSERT INTO property_details
VALUES (0, NOW(), '$ID', '$add_owner', '$add_block', '$add_road', '$add_house', '$add_unit', '$add_area', '$add_postcode', '$add_zone', '$prop_cat', '$prop_hot', 'Active', '$prop_contact', '$prop_type', '$prop_saletype', '$prop_desc', '$prop_tenure', '$prop_bedroom', '$prop_bathroom', '$prop_price', '$prop_garage', '$prop_park', '$prop_pool', '$prop_garden', '$prop_alarm', '$prop_appliance', '$screenpath', '$image_main_name', '$image_kitchen_name', '$image_bed_name', '$image_bath_name', '$image_living_name', '$image_dining_name', '$image_garden_name')";
                      
  mysqli_query($dbc, $query);
// Confirm success with the user - have removed for sake of brevity.
		   	    ?>

Instead of all the "rand" stuff, probably better to use uniqid(), which does exactly that.

commented: yes +5

Wow, I learned something new! I've never seen the uniqid(); function before. Though, I like the random function I made because you can specify, uppercase, lowercase, numbers, symbols and also the length. The uniqid() function by far meets the needs of the script, though, it may be insecure since it is based off of the microsecond clock on the server. If for instance, you use this as a variable to validate email addresses, someone can generate a few thousand numbers based off of the time their request was made and regenerate those numbers...Unless you prevent brute force attempts, which is a whole other chunck of messy code!

I know this is marked as solved but I've done this before and wanted to add my two cents if I may.

I have a custom CMS that does this, and here is my process, which I feel is pretty simple, as all images can be in the same directory:
1. Save the original file name to a variable ($name)
2. Generate a unique name to replace the file. I used rand() as part of a loop that checks the database to make sure the random number isn't already in use. If the loop finds a match, it starts over again with a new rand().
3. When you've got your unique random number, rename the file with that number and save it to your preferred directory.
4. Save the original file name ($name) to your database together with the new file name.
5. For display purposes, you can use the original file name (like "kitchen.jpg") so the user can identify the image. But in your business logic, you actually only use "kitchen.jpg" for display- file management uses the random file name generated above.

Hope that helps someone!

commented: Thanks for sharing +5

Hi Yes thanks. and I'll probably have to do something like that in my 'edit property'forms, where it will not be exactly the same due to having the old image there. Many thanks for the input. It has been great.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.