• 0

Uploading Photos, creating directory and updating row in table.


Question

I am trying to update a table row by adding photos. Now everything in the code below works, except it cannot work fully until I can get the $name = $_GET['name']; to read from the row in the table. If someone can help get it to detect this part then the rest should work.

These are the errors I get because I do not have the name displaying from the property details when creating the directory.

Warning: mkdir(http://www.site.com/photos/properties/username/) [function.mkdir]: No such file or directory in 

/home/account/public_html/panel/write-photos.php on line 158

Warning: move_uploaded_file(http://www.site.com/photo/properties/username/) [function.move-uploaded-file]: failed to open 

stream: HTTP wrapper does not support writeable connections. in /home/account/public_html/panel/write-photos.php on line 160

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpv1BtAb' to 

'http://www.site.com/photo/properties/username/' in /home/account/public_html/panel/write-photos.php on line 160

Warning: chmod() [function.chmod]: No such file or directory in /home/account/public_html/panel/write-photos.php on line 161

If you read the code below carefully you will see that the other POST fields are there becuase they are not to be overwritten.

This is the full page:-

<?
$sql = mysql_query("SELECT * FROM properties WHERE property_id='$id' AND username = '$session->username'");
while($propertyRow = mysql_fetch_array($sql))
	{
	$id = $propertyRow['property_id'];
	$status = $propertyRow['status'];
	$saletype = $propertyRow['sale_type'];
	$category = $propertyRow['category'];
	$name = $propertyRow['name'];
	$address = $propertyRow['address'];
	$village = $propertyRow['village'];
	$long = $propertyRow['long'];
	$lat = $propertyRow['lat'];
	$department = $propertyRow['department'];
	$postcode = $propertyRow['postcode'];
	$price = $propertyRow['price'];
	$featured = $propertyRow['featured'];
	$dateentered = $propertyRow['date_entered'];
	$sec = substr($propertyRow['date_entered'],17,2);
	$minute= substr($propertyRow['date_entered'],14,2);
	$hour = substr($propertyRow['date_entered'],11,2);
	$day = substr($propertyRow['date_entered'],8,2);
	$month = substr($propertyRow['date_entered'],5,2);
	$year = substr($propertyRow['date_entered'],0,4);
	$date_entered = $day."/".$month."/".$year." ".$hour.":".$minute.":".$sec;
	}
?>
<form action="write-photos.php?mode=update&?id=<? echo $id; ?>" method="post" enctype="multipart/form-data" style="border:0px; 

padding:0px; margin:0px;">
<?
if($_GET['mode'] == "update")
	{
	$id = $_GET['property_id'];
	$name = $_GET['name'];
	///// Upload Photos /////
	foreach ($_FILES["photo"]["error"] as $key => $error) 
	{
		if ($error == UPLOAD_ERR_OK){
			$tmp_name = $_FILES["photo"]["tmp_name"][$key];
			$photo = $_FILES["photo"]["file"][$key];
			mkdir("$SITEurl/photos/properties/$session->username/$name",0777);
			$file = preg_replace("/([^a-z0-9])+/i", "-", $photo);
			move_uploaded_file($tmp_name, "$SITEurl/photo/properties/$session->username/$name");
			chmod("$SITEurl/photo/properties/$session->username/$name", 0777);
			$picno = $key;
			$PHOTO[] = $photo;
			$sqlphoto = "UPDATE properties SET photo$picno = '$name' WHERE property_id = '$id'";
				if(@mysql_query($sqlphoto)){
					$msg = "Photo ".$picno." ".$photo." uploaded.</br>";
			}else{
					echo mysql_error();
			}
		}
	}
		///// Add Properties to DB /////
		$dateentered  = date("Y:m:d H:i:s");
		$status = $_POST['status'];
		$sale_type = $_POST['sale_type'];
		$category = $_POST['category'];
		$name = addslashes($_POST['name']);
		$address = $_POST['address'];
		$village = $_POST['village'];
		$lng = $_POST['lng'];
		$lat = $_POST['lat'];
		$department = $_POST['department'];
		$telephone = $_POST['telephone'];
		$mobile = $_POST['mobile'];
		$email = $_POST['email'];
		$description_fr = addslashes($_POST['description_fr']);
		$description_en = addslashes($_POST['description_en']);
		$price = $_POST['price'];
		$bedrooms = $_POST['bedrooms'];
		$bathrooms = $_POST['bathrooms'];
		$view = $_POST['view'];
		$meters = $_POST['meters'];
		$terrain = $_POST['terrain'];
		$pool = $_POST['pool'];
		$garage = $_POST['garage'];
		$garage_size = $_POST['garage_size'];
		$front_garden = $_POST['front_garden'];
		$rear_garden = $_POST['rear_garden'];
		$int_features = $_POST['int_features']; 
		$ext_features = $_POST['ext_features']; 
		$fees = $_POST['fees'];
		$tax = $_POST['tax'];
		if(isset($_POST['username']))
			{
			$username = serialize($_POST['username']);
			}else
				{
				$username = "";
				}
		if(isset($_POST['int_features']))
			{
			$int_features = serialize($_POST['int_features']);
			}else
				{
				$int_features = "";
				}
		if(isset($_POST['ext_features']))
			{
			$ext_features = serialize($_POST['ext_features']);
			}else
				{
				$ext_features = "";
				}
$sql = "UPDATE properties SET ('$id', '$session->username', '$dateentered', '$status', '$sale_type', '$category', '$name', 

'$address', '$village', '$lng', '$lat', '$department', '$postcode', '$telephone', '$mobile', '$email', '$description_fr', 

'$description_en', '$price', '', '$bedrooms', '$bathrooms', '$view', '$meters', '$terrain', '$pool', '$garage', '$garage_size', 

'$front_garden', '$rear_garden', '$int_features', '$ext_features', '$video_tour', 'no', '$fees', '$tax', '$PHOTO[1]', '$PHOTO

[2]', '$PHOTO[3]', '$PHOTO[4]', '$PHOTO[5]', '$PHOTO[6]', '$PHOTO[7]', '$PHOTO[8]', '$PHOTO[9]', '$PHOTO[10]', '$PHOTO[11]', 

'$PHOTO[12]', '', '', '', '1')";
	if(@mysql_query($sql))
	{
	$msg = "Your have succesfully added your photos to the property";
	}else{
	$msg = "There was an error uploading the photos, please contact <a href=\"mailto:[email protected]\">administrators</a> 

for help!";
	}
}
?>		
<div id="content">
	<? echo "<h3>".$msg."</h3>"; ?>
	<div id="sidebar-left">
	<ul id="post_options">
		<li class="current">Brief Details on Property</li>
		<li>ID: <? echo $id; ?><br>Name: <? echo $name; ?><br>Department: <? echo $department; ?><br>Price €<? 

echo $price; ?><br><br>Date Posted: <? echo $dateentered; ?></li>
		<li class="finish">Finished Adding Photos?</li>
		<li><select id="post_status" name="status" onchange="if (this.selectedIndex==1){this.form

['check'].style.visibility='visible'}else {this.form['check'].style.visibility='hidden'};">
			<option value="">no</option>
			<option value="">yes</option>
			</select></li>
		<li>
		<b><font color="#0099FF">Please double check your photos are in order as 
		you want them before attaching to the property.</font></b><br><br>
		<input type="checkbox" name="check" style="visibility:hidden;" onclick="this.form.Submit.disabled = !

this.checked;">Enable Save<br><br>
		<input class="save" name="Submit" type="submit" value="Save" disabled="disabled"></li>
		<li class="related"><b>Related Links</b></li>
		<li><a href="manage.php">Manage All Your Properties</a></li>
		<li><a href="manage-draft.php">View Your Drafts</a></li>
	</ul>
	</div>

	<div id="write-property">
	<script type="text/javascript">
	/* This function is called when user selects file in file dialog */
	function checkext(upload_field) 
	{
		var re_text = /\.jpeg|\.jpg/i;
		var filename = upload_field.value;
		/* Checking file type */
		if (filename.search(re_text) == -1)
		{
			alert("Please select a JPEG file.");
			upload_field.value = '';
		}
		return true;
	}
	</script>
	<table width="100%" border="0" cellpadding="0" cellspacing="4">
		<tr>
			<td>Main Photo</td>
			<td><input name="photo[1]" type="file" id="photo[1]" title="This field is required" size="30" 

onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 2</td>
			<td><input name="photo[2]" type="file" id="photo[2]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 3</td>
			<td><input name="photo[3]" type="file" id="photo[3]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 4</td>
			<td><input name="photo[4]" type="file" id="photo[4]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 5</td>
			<td><input name="photo[5]" type="file" id="photo[5]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 6</td>
			<td><input name="photo[6]" type="file" id="photo[6]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 7</td>
			<td><input name="photo[7]" type="file" id="photo[7]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 8</td>
			<td><input name="photo[8]" type="file" id="photo[8]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 9</td>
			<td><input name="photo[9]" type="file" id="photo[9]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 10</td>
			<td><input name="photo[10]" type="file" id="photo[10]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 11</td>
			<td><input name="photo[11]" type="file" id="photo[11]" size="30" onChange="return checkext(this)"></td>
		</tr>
		<tr>
			<td>Photo 12</td>
			<td><input name="photo[12]" type="file" id="photo[12]" size="30" onChange="return checkext(this)"></td>
		</tr>
	</table>
	</div>
</div>
<input name="MAX_FILE_SIZE" type="hidden" value="<?php echo $MAXimagesize; ?>">
</form>

This is the part that needs fixing:-

if($_GET['mode'] == "update")
	{
	$id = $_GET['property_id'];
	$name = $_GET['name'];
	///// Upload Photos /////
	foreach ($_FILES["photo"]["error"] as $key => $error) 
	{
		if ($error == UPLOAD_ERR_OK){
			$tmp_name = $_FILES["photo"]["tmp_name"][$key];
			$photo = $_FILES["photo"]["file"][$key];
			mkdir("$SITEurl/photos/properties/$session->username/$name",0777);
			$file = preg_replace("/([^a-z0-9])+/i", "-", $photo);
			move_uploaded_file($tmp_name, "$SITEurl/photo/properties/$session->username/$name");
			chmod("$SITEurl/photo/properties/$session->username/$name", 0777);
			$picno = $key;
			$PHOTO[] = $photo;
			$sqlphoto = "UPDATE properties SET photo$picno = '$name' WHERE property_id = '$id'";
				if(@mysql_query($sqlphoto)){
					$msg = "Photo ".$picno." ".$photo." uploaded.</br>";
			}else{
					echo mysql_error();
			}
		}
	}

Now if the error was to show again because of something else the warning should read like this:-

Warning: mkdir(http://www.site.com/photos/properties/username/name) [function.mkdir]: No such file or directory in

/home/account/public_html/panel/write-photos.php on line 158

Warning: move_uploaded_file(http://www.site.com/photo/properties/username/name) [function.move-uploaded-file]: failed to open

stream: HTTP wrapper does not support writeable connections. in /home/account/public_html/panel/write-photos.php on line 160

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpv1BtAb' to

'http://www.site.com/photo/properties/username/name' in /home/account/public_html/panel/write-photos.php on line 160

Warning: chmod() [function.chmod]: No such file or directory in /home/account/public_html/panel/write-photos.php on line 161

Notice name in bold, that part is not reading from the table, that is whats missing. I would really like to get this to work.

20 answers to this question

Recommended Posts

  • 0

1) you're using <? again instead of <?php. stop it stop it stop it stop it stop it. please.

2) what on earth is going on at the start, you're grabbing records from the database, then for each one overwriting the contents of load of variables, the end result of which is that you've simply copied the data from the last result...

if you're trying to do stuff for multiple records from the database, then you've failed to do so! if you're trying to do stuff for just one user then: i) add LIMIT 1 to the end of your query ii) add a check to make sure a user record has been found and if not display an error iii) and then three put $propertyRow = mysql_fetch_array($sql); within the braces and get rid of the while statement.

infact why bother extracting the data into separate variables, it's a waste of time! the data is already in an array, leave it there! if you think $propertyRow['status'] is a bit long rename the array so it's something like just $data['status']? one problem to note is when using array entries in a string, you need to wrap it in braces e.g. echo "text {$arr['data']} text";.

3) on lines 34 and 35 you're trying to get the name and id, however these are not set in the url!!!

you're also trying to get loads of other data from your form in lines 58-107 which as far as i can tell, also don't exist

you REALLY need to throw in that code i gave you previously to force all errors to display!

  • 0

Another major issue with your code, aside from what theblazingangel said is your use of the mkdir(), move_uploaded_file(), and chmod() functions. You cannot use a URL with any of these functions. You must provide the absolute (real) filesystem path. See the PHP manual page for mkdir(), chmod(), and move_uploaded_file().

  • 0

Just for the hell of it heres my pic upload script with mysql entry.

Modify it as you wish

 if (isset($_POST['submit'])) {
  $file_upload="true";
 if (isset($_FILES['userfile']['size']) &amp;&amp; $_FILES['userfile']['size']&gt;300000){
  $var = "Your uploaded file size is more than 300KB so please reduce the file size and then upload.&lt;BR&gt;";
  $file_upload="false";
}
if (isset($_FILES['userfile']['type']) &amp;&amp; !($_FILES['userfile']['type'] =="image/jpeg" OR $_FILES['userfile']['type'] =="image/png" OR $_FILES['userfile']['type'] =="image/gif")){
 $var = "Your uploaded file must be of JPG or GIF. Other file types are not allowed&lt;BR&gt;";
 $file_upload="false";
}

if($file_upload=="true") {
 $uploadfile = 'memberuploads/' . $_FILES['userfile']['name'];
 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){
  $var = "Successfully Uploaded";
  $image = $_FILES['userfile']['name'];
  mysql_query("UPDATE members SET image = '$image' WHERE name = '$name'");
 } 
 else {
  $var = "Failed to upload file";
 }
}
}
}

The form

&lt;form enctype="multipart/form-data" action="editpersonalpage.php?option=pic" method=POST style='padding: 0; margin: 0;'&gt;
Upload this file: &lt;input name="userfile" type="file"&gt;
&lt;input type="checkbox" name="picdefault"&gt;
&lt;span style='font-size:12;'&gt;Restore Default?&lt;br/&gt;&lt;br/&gt;
&lt;input type="submit" VALUE="Send File" name='submit'&gt;&lt;/FORM&gt;
&lt;?if (isset($var)) { echo $var; }?&gt;&lt;/span&gt;

Also i'm not sure quite whats going on with your $_FILES["photo"]["file"][$key] thing. I thought you just had to use that string without the key..? Maybe you need ' instead of " in it to.

Edited by dave164
  • 0

Ok I have fixed a number of errors for uploading the photos and it works but it still needs a bit of work as it comes up with the same error for the other 11 photos that are uploaded.

Warning: mkdir(../photos/properties/username/name/) [function.mkdir]: File exists in /home/account/public_html/panel/write-photos.php on line 138

This should not show and it should be trying to create the directory once.

Now the main problem I have once the photos have been uploaded to the directory set is that the database does not update the id with the photos filename.

There are 12 photos in total that the user can upload maximum. All 12 upload succesfully but the database does nothing with the values. Now maybe they are in the wrong place or they are not there and I have'nt realised were they are missing or something else is causing the database not to update the database with the 12 photos. Also it does not update the 'last_edit' value with the date when the user started to edit the property to add the photos. I have posted the latest code of the page below along with my property table structure. I hope some one can help me get it to work.

Property Table Structure

  `property_id` int(11) NOT NULL auto_increment,
  `username` varchar(20) collate utf8_bin NOT NULL,
  `date_entered` datetime NOT NULL default '0000-00-00 00:00:00',
  `status` varchar(20) collate utf8_bin NOT NULL default 'Draft',
  `sale_type` varchar(255) collate utf8_bin NOT NULL,
  `category` varchar(255) collate utf8_bin NOT NULL,
  `name` varchar(255) collate utf8_bin NOT NULL default '',
  `address` varchar(255) collate utf8_bin NOT NULL default '',
  `village` varchar(255) collate utf8_bin NOT NULL,
  `lng` float(10,6) NOT NULL,
  `lat` float(10,6) NOT NULL,
  `department` varchar(255) collate utf8_bin NOT NULL,
  `postcode` varchar(255) collate utf8_bin NOT NULL,
  `telephone` varchar(255) collate utf8_bin NOT NULL default '',
  `mobile` varchar(255) collate utf8_bin NOT NULL,
  `email` varchar(255) collate utf8_bin NOT NULL default '',
  `description_fr` text collate utf8_bin NOT NULL,
  `description_en` text collate utf8_bin NOT NULL,
  `price` varchar(255) collate utf8_bin NOT NULL,
  `price_change` varchar(255) collate utf8_bin NOT NULL default 'no',
  `bedrooms` char(1) collate utf8_bin NOT NULL default '0',
  `bathrooms` char(1) collate utf8_bin NOT NULL default '0',
  `view` varchar(255) collate utf8_bin NOT NULL default '',
  `meters` varchar(20) collate utf8_bin NOT NULL,
  `terrain` varchar(255) collate utf8_bin NOT NULL,
  `pool` varchar(3) collate utf8_bin NOT NULL default 'no',
  `garage` varchar(3) collate utf8_bin NOT NULL default 'no',
  `garage_size` varchar(11) collate utf8_bin NOT NULL default '',
  `front_garden` varchar(5) collate utf8_bin NOT NULL,
  `rear_garden` varchar(5) collate utf8_bin NOT NULL,
  `int_features` text collate utf8_bin NOT NULL,
  `ext_features` text collate utf8_bin NOT NULL,
  `video_tour` text collate utf8_bin NOT NULL,
  `featured` char(3) collate utf8_bin NOT NULL default 'no',
  `fees` varchar(255) collate utf8_bin NOT NULL default '',
  `tax` varchar(255) collate utf8_bin NOT NULL default '',
  `photo1` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo2` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo3` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo4` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo5` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo6` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo7` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo8` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo9` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo10` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo11` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `photo12` varchar(255) collate utf8_bin NOT NULL default 'empty',
  `visits` varchar(255) collate utf8_bin NOT NULL,
  `last_visit` datetime NOT NULL default '0000-00-00 00:00:00',
  `last_edit` datetime NOT NULL default '0000-00-00 00:00:00',
  `active` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`property_id`),
  KEY `user_id` (`username`),
  FULLTEXT KEY `category` (`category`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='This table stores the properties posted by the users.' AUTO_INCREMENT=1;

write-photos.php

&lt;?php
if($_GET['mode'] == "update")
	{
	$id = $_GET['property_id'];
		if(isset($_POST['username']))
			{
			$username = serialize($_POST['username']);
		}else{
			$username = "";
			}
		if(isset($_POST['int_features']))
			{
			$int_features = serialize($_POST['int_features']);
		}else{
			$int_features = "";
			}
		if(isset($_POST['ext_features']))
			{
			$ext_features = serialize($_POST['ext_features']);
		}else{
			$ext_features = "";
			}
	///// Upload Photos /////
	$picname = str_replace(" ","_",$_POST['name']);
	foreach ($_FILES["photo"]["error"] as $key =&gt; $error)
	{
	if ($error == UPLOAD_ERR_OK){
		$tmp_name = $_FILES["photo"]["tmp_name"][$key];
		$photo = $_FILES["photo"]["name"][$key];
		mkdir("../photos/properties/$session-&gt;username/$name/",0777);
		$photo = preg_replace("/([^a-z0-9])+/i", ".", $photo);
		move_uploaded_file($tmp_name, "../photos/properties/$session-&gt;username/$name/$photo");
		chmod("../photos/properties/$session-&gt;username/$name/$photo", 0777);
		$msg = "Photo ".$picno." ".$photo." uploaded.&lt;/br&gt;";
		$picno = $key;
		$PHOTO[] = $photo;
		$sqlphoto = "UPDATE properties SET photo$picno = '$photo' WHERE property_id = '$id'";
		if(@mysql_query($sqlphoto)){
			$msg = "Your have succesfully added your photos to this property!&lt;br&gt;";
		}else{
			$msg = "There was an error uploading the photos, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
		}
	}
}
		///// Update Property to DB /////
		$newname = str_replace(" ","_",$photo);
		$status = $_POST['status'];
		$sale_type = $_POST['sale_type'];
		$category = $_POST['category'];
		$name = addslashes($_POST['name']);
		$address = $_POST['address'];
		$village = $_POST['village'];
		$lng = $_POST['lng'];
		$lat = $_POST['lat'];
		$department = $_POST['department'];
		$postcode = $_POST['postcode'];
		$description_fr = addslashes($_POST['description_fr']);
		$description_en = addslashes($_POST['description_en']);
		$price = $_POST['price'];
		$bedrooms = $_POST['bedrooms'];
		$bathrooms = $_POST['bathrooms'];
		$view = $_POST['view'];
		$meters = $_POST['meters'];
		$terrain = $_POST['terrain'];
		$pool = $_POST['pool'];
		$garage = $_POST['garage'];
		$garage_size = $_POST['garage_size'];
		$front_garden = $_POST['front_garden'];
		$rear_garden = $_POST['rear_garden'];
		$int_features = $_POST['int_features'];
		$ext_features = $_POST['ext_features'];
		$fees = $_POST['fees'];
		$tax = $_POST['tax'];
		$photo1 = $_POST['photo1'];
		$photo2 = $_POST['photo2'];
		$photo3 = $_POST['photo3'];
		$photo4 = $_POST['photo4'];
		$photo5 = $_POST['photo5'];
		$photo6 = $_POST['photo6'];
		$photo7 = $_POST['photo7'];
		$photo8 = $_POST['photo8'];		
		$photo9 = $_POST['photo9'];
		$photo10 = $_POST['photo10'];		
		$photo11 = $_POST['photo11'];
		$photo12 = $_POST['photo12'];
		$lastedit  = date("Y:m:d H:i:s");
	$sql = "UPDATE properties SET status = '$status', sale_type = '$sale_type', category ='$category', name = '$name', address = '$address', village = '$village', lng = '$lng', lat = '$lat', department = '$department', postcode = '$postcode', last_edit = '$lastedit' WHERE property_id = '$id'";
	if(@mysql_query($sql)){
		$msg = "Congratulations, your property &lt;b&gt;".$name."&lt;/b&gt; is now complete. If you set your property status to Draft click &lt;a href=\"manage-edit.php?id=$id\"&gt;here&lt;/a&gt; to change it to Published!";
	}else{
		$msg = "We will make sure that your photos are added to your property asap.";
	}
}
?&gt;

&lt;?php
$sql = mysql_query("SELECT * FROM properties WHERE property_id='$id' AND username = '$session-&gt;username'");
while($propertyRow = mysql_fetch_array($sql))
	{
	$id = $propertyRow['property_id'];
	$status = $propertyRow['status'];
	$saletype = $propertyRow['sale_type'];
	$category = $propertyRow['category'];
	$name = $propertyRow['name'];
	$address = $propertyRow['address'];
	$village = $propertyRow['village'];
	$long = $propertyRow['long'];
	$lat = $propertyRow['lat'];
	$department = $propertyRow['department'];
	$postcode = $propertyRow['postcode'];
	$price = $propertyRow['price'];
	$lastedit = $propertyRow['last_edit'];
	$dateentered = $propertyRow['date_entered'];
	$sec = substr($propertyRow['date_entered'],17,2);
	$minute= substr($propertyRow['date_entered'],14,2);
	$hour = substr($propertyRow['date_entered'],11,2);
	$day = substr($propertyRow['date_entered'],8,2);
	$month = substr($propertyRow['date_entered'],5,2);
	$year = substr($propertyRow['date_entered'],0,4);
	$date_entered = $day."/".$month."/".$year." ".$hour.":".$minute.":".$sec;
	}
?&gt;
&lt;form action="write-photos.php?mode=update&amp;?id=&lt;? echo $id; ?&gt;" method="post" enctype="multipart/form-data" style="border:0px; padding:0px; margin:0px;"&gt;
&lt;div id="content"&gt;
	&lt;h2&gt;&lt;? echo getLang('attachphotos'); ?&gt;&lt;/h2&gt;
	&lt;? echo "&lt;h3&gt;".$msg."&lt;/h3&gt;"; ?&gt;
	&lt;div id="sidebar-left"&gt;
	&lt;ul id="post_options"&gt;
		&lt;li class="current"&gt;&lt;? echo getLang('briefdetails'); ?&gt;&lt;/li&gt;
		&lt;li&gt;ID: &lt;? echo $id; ?&gt;&lt;br&gt;&lt;? echo getLang('name'); ?&gt;: &lt;? echo $name; ?&gt;&lt;br&gt;&lt;? echo getLang('department'); ?&gt;: &lt;? echo $department; ?&gt;&lt;br&gt;&lt;? echo getLang('price'); ?&gt; ?&lt;? echo $price; ?&gt;&lt;br&gt;&lt;br&gt;&lt;? echo getLang('dateposted'); ?&gt;: &lt;? echo $dateentered; ?&gt;&lt;/li&gt;
		&lt;li class="finish"&gt;&lt;? echo getLang('finishedadding'); ?&gt;&lt;/li&gt;
		&lt;li&gt;&lt;select id="post_status" name="status" onchange="if (this.selectedIndex==1){this.form['check'].style.visibility='visible'}else {this.form['check'].style.visibility='hidden'};"&gt;
			&lt;option value=""&gt;&lt;? echo getLang('no'); ?&gt;&lt;/option&gt;
			&lt;option value=""&gt;&lt;? echo getLang('yes'); ?&gt;&lt;/option&gt;
			&lt;/select&gt;&lt;/li&gt;
		&lt;li&gt;
		&lt;b&gt;&lt;font color="#0099FF"&gt;&lt;? echo getLang('checkphotos'); ?&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;
		&lt;input type="checkbox" name="check" style="visibility:hidden;" onclick="this.form.Submit.disabled = !this.checked;"&gt;&lt;? echo getLang('enablesave'); ?&gt;&lt;br&gt;&lt;br&gt;
		&lt;input class="save" name="Submit" type="submit" value="&lt;? echo getLang('save'); ?&gt;" disabled="disabled"&gt;&lt;/li&gt;
		&lt;li class="related"&gt;&lt;b&gt;&lt;? echo getLang('relatedlinks'); ?&gt;&lt;/b&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="manage.php"&gt;&lt;? echo getLang('manageyourproperties'); ?&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="manage-draft.php"&gt;&lt;? echo getLang('viewyourdrafts'); ?&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;/div&gt;

	&lt;div id="write-property"&gt;
	&lt;script type="text/javascript"&gt;
	/* This function is called when user selects file in file dialog */
	function checkext(upload_field)
	{
		var re_text = /\.jpeg|\.jpg/i;
		var filename = upload_field.value;
		/* Checking file type */
		if (filename.search(re_text) == -1)
		{
			alert("Please select a JPEG file.");
			upload_field.value = '';
		}
		return true;
	}
	&lt;/script&gt;
	&lt;table width="100%" border="0" cellpadding="0" cellspacing="4"&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo1'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[1]" type="file" id="photo[1]" title="&lt;? echo getLang('fieldrequired'); ?&gt;" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo2'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[2]" type="file" id="photo[2]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo3'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[3]" type="file" id="photo[3]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo4'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[4]" type="file" id="photo[4]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo5'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[5]" type="file" id="photo[5]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo6'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[6]" type="file" id="photo[6]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo7'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[7]" type="file" id="photo[7]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo8'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[8]" type="file" id="photo[8]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo9'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[9]" type="file" id="photo[9]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo10'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[10]" type="file" id="photo[10]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo11'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[11]" type="file" id="photo[11]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;&lt;? echo getLang('photo12'); ?&gt;&lt;/td&gt;
			&lt;td&gt;&lt;input name="photo[12]" type="file" id="photo[12]" size="30" onChange="return checkext(this)"&gt;&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	&lt;/div&gt;
&lt;/div&gt;
&lt;input name="MAX_FILE_SIZE" type="hidden" value="&lt;?php echo $MAXimagesize; ?&gt;"&gt;
&lt;input name="name" type="hidden" value="&lt;? echo $name; ?&gt;"&gt;
&lt;input name="last_edit" type="hidden" id="last_edit" value="&lt;? echo $lastedit; ?&gt;"&gt;
&lt;/form&gt;

Look forward to your answers.

  • 0

	///// Upload Photos /////
	$picname = str_replace(" ","_",$_POST['name']);
	foreach ($_FILES["photo"]["error"] as $key =&gt; $error)
	{
	if ($error == UPLOAD_ERR_OK){
		$tmp_name = $_FILES["photo"]["tmp_name"][$key];
		$photo = $_FILES["photo"]["name"][$key];
		mkdir("../photos/properties/$session-&gt;username/$name/",0777);
		$photo = preg_replace("/([^a-z0-9])+/i", ".", $photo);
		move_uploaded_file($tmp_name, "../photos/properties/$session-&gt;username/$name/$photo");
		chmod("../photos/properties/$session-&gt;username/$name/$photo", 0777);
		$msg = "Photo ".$picno." ".$photo." uploaded.&lt;/br&gt;";
		$picno = $key;
		$PHOTO[] = $photo;
		$sqlphoto = "UPDATE properties SET photo$picno = '$photo' WHERE property_id = '$id'";
		if(@mysql_query($sqlphoto)){
			$msg = "Your have succesfully added your photos to this property!&lt;br&gt;";
		}else{
			$msg = "There was an error uploading the photos, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
		}
	}
}

Your main problem here is where you are trying to include the pic number in the SQL query. You cannot simply but a variable name against plaintext and have PHP parse it. You should do this to make PHP parse the variable correctly:

$sqlphoto = "UPDATE properties SET photo{$picno} = '$photo' WHERE property_id = '$id'";

Also in the above snippet that I quoted, you are creating a new array $PHOTO[], but are not using it anywhere. Is this intentional for future?

Secondly, the snippet I've quoted below refers to $_POST['photo1'] and so on, however, the snippet above shows that they are in an array. That's another part of your problem, although you are not using them at any point in the SQL query either.

///// Update Property to DB /////
		$newname = str_replace(" ","_",$photo);
		$status = $_POST['status'];
		$sale_type = $_POST['sale_type'];
		$category = $_POST['category'];
		$name = addslashes($_POST['name']);
		$address = $_POST['address'];
		$village = $_POST['village'];
		$lng = $_POST['lng'];
		$lat = $_POST['lat'];
		$department = $_POST['department'];
		$postcode = $_POST['postcode'];
		$description_fr = addslashes($_POST['description_fr']);
		$description_en = addslashes($_POST['description_en']);
		$price = $_POST['price'];
		$bedrooms = $_POST['bedrooms'];
		$bathrooms = $_POST['bathrooms'];
		$view = $_POST['view'];
		$meters = $_POST['meters'];
		$terrain = $_POST['terrain'];
		$pool = $_POST['pool'];
		$garage = $_POST['garage'];
		$garage_size = $_POST['garage_size'];
		$front_garden = $_POST['front_garden'];
		$rear_garden = $_POST['rear_garden'];
		$int_features = $_POST['int_features'];
		$ext_features = $_POST['ext_features'];
		$fees = $_POST['fees'];
		$tax = $_POST['tax'];
		$photo1 = $_POST['photo1'];
		$photo2 = $_POST['photo2'];
		$photo3 = $_POST['photo3'];
		$photo4 = $_POST['photo4'];
		$photo5 = $_POST['photo5'];
		$photo6 = $_POST['photo6'];
		$photo7 = $_POST['photo7'];
		$photo8 = $_POST['photo8'];		
		$photo9 = $_POST['photo9'];
		$photo10 = $_POST['photo10'];		
		$photo11 = $_POST['photo11'];
		$photo12 = $_POST['photo12'];
		$lastedit  = date("Y:m:d H:i:s");
	$sql = "UPDATE properties SET status = '$status', sale_type = '$sale_type', category ='$category', name = '$name', address = '$address', village = '$village', lng = '$lng', lat = '$lat', department = '$department', postcode = '$postcode', last_edit = '$lastedit' WHERE property_id = '$id'";
	if(@mysql_query($sql)){
		$msg = "Congratulations, your property &lt;b&gt;".$name."&lt;/b&gt; is now complete. If you set your property status to Draft click &lt;a href=\"manage-edit.php?id=$id\"&gt;here&lt;/a&gt; to change it to Published!";
	}else{
		$msg = "We will make sure that your photos are added to your property asap.";
	}
}
?&gt;

  • 0

I changed the part of code with what you gave me and nothing has changed to the database.

$sqlphoto = "UPDATE properties SET photo{$picno} = '$photo' WHERE property_id = '$id'";

This $PHOTO[] = $photo; is suppose to help update the database by setting as $PHOTO[1] = $photo, $PHOTO[2] = $photo and so on, but I guess it doesn't because maybe something is missing. I would of thought that $key would autogenerate the number of the photo and place it in like so $PHOTO[$key].

Should I also remove these since they don't seem to be doing anything.

$photo1 = $_POST['photo1'];
$photo2 = $_POST['photo2'];
$photo3 = $_POST['photo3'];
$photo4 = $_POST['photo4'];
$photo5 = $_POST['photo5'];
$photo6 = $_POST['photo6'];
$photo7 = $_POST['photo7'];
$photo8 = $_POST['photo8'];		
$photo9 = $_POST['photo9'];
$photo10 = $_POST['photo10'];		
$photo11 = $_POST['photo11'];
$photo12 = $_POST['photo12'];

  • 0
haven't got time at the minute to look at your code properly, but if your form field is name="photo[]" then you need to access it with $_POST['photo'][1] (i believe)

I tried that, didn't do anything and don't forget I am allowing the user to upload 12 photos in total, no more. And I only want one directory created not having the function do it again 11 more times.

EDIT: I also tried this and still nothing happened.

$sqlphoto = "UPDATE properties SET photo1 = '$photo', photo2 = '$photo', photo3 = '$photo', photo4 = '$photo', photo5 = '$photo', photo6 = '$photo', photo7 = '$photo', photo8 = '$photo', photo9 = '$photo', photo10 = '$photo', photo11 = '$photo', photo12 = '$photo' WHERE property_id = '$id'";

Edited by admin2gd1
  • 0

try this code and see where we get. it's pretty hard to know for certain there are no problems with it because i can't actually run it. to run it i need all the rest of your code, structures of all your database tables, and sample data from all of your tables.

&lt;?php
if ( (isset($_GET['mode']) &amp;&amp; ($_GET['mode'] == "update") )
{
	$id = $_GET['id'];
	$username = (isset($_POST['username'])) ? serialize($_POST['username']) : '';
	$int_features = (isset($_POST['int_features'])) ? serialize($_POST['int_features']) : '';
	$ext_features = (isset($_POST['ext_features'])) ? serialize($_POST['ext_features']) : '';

	///// Upload Photos /////
	$PHOTOS = array();
	$picname = str_replace(" ","_",$_POST['name']);
	foreach ($_FILES["photo"]["error"] as $key =&gt; $error)
	{
		if ($error == UPLOAD_ERR_OK)
		{
			$tmp_name = mysql_real_escape_string($_FILES["photo"]["tmp_name"][$key]);
			$photo = mysql_real_escape_string($_FILES["photo"]["name"][$key]);
			mkdir("../photos/properties/$session-&gt;username/$name/",0777);
			$photo = preg_replace("/([^a-z0-9])+/i", ".", $photo);
			move_uploaded_file($tmp_name, "../photos/properties/{$session-&gt;username}/$name/$photo");
			chmod("../photos/properties/{$session-&gt;username}/$name/$photo", 0777);
			$picno = $key;
			$msg = "Photo ".$picno." ".$photo." uploaded.&lt;br /&gt;";
			$PHOTO[$picno] = $photo;
		} else {
			$msg = "Photo number $key failed to upload!&lt;br /&gt;";
		}
	}

	$PHOTOS_SQL = array();
	foreach ($PHOTOS as $key =&gt; $value)
	{
		$PHOTOS_SQL[] = "`photo{$key}`='{$value}'";
	}
	if (! empty($PHOTOS_SQL))
	{
		$PHOTOS_SQL = implode(', ', $PHOTOS_SQL);
		$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL} WHERE `property_id`='$id'";
		if(mysql_query($sqlphotos))
		{
			$msg = "Successfully added uploaded photos to this property!&lt;br&gt;";
		}else{
			$msg = "There was an error adding uploaded photos to the property, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
		}
	} else {
		$msg = "No uploaded photos to attach to the property!";
	}

	///// Update Property to DB /////
	$newname = str_replace(" ","_",$photo);
	$status = mysql_real_escape_string($_POST['status']);
	$sale_type = mysql_real_escape_string($_POST['sale_type']);
	$category = mysql_real_escape_string($_POST['category']);
	$name = addslashes(mysql_real_escape_string($_POST['name']));
	$address = mysql_real_escape_string($_POST['address']);
	$village = mysql_real_escape_string($_POST['village']);
	$lng = mysql_real_escape_string($_POST['lng']);
	$lat = mysql_real_escape_string($_POST['lat']);
	$department = mysql_real_escape_string($_POST['department']);
	$postcode = mysql_real_escape_string($_POST['postcode']);
	$description_fr = addslashes(mysql_real_escape_string($_POST['description_fr']));
	$description_en = addslashes(mysql_real_escape_string($_POST['description_en']));
	$price = mysql_real_escape_string($_POST['price']);
	$bedrooms = mysql_real_escape_string($_POST['bedrooms']);
	$bathrooms = $_POST['bathrooms'];
	$view = mysql_real_escape_string($_POST['view']);
	$meters = mysql_real_escape_string($_POST['meters']);
	$terrain = mysql_real_escape_string($_POST['terrain']);
	$pool = mysql_real_escape_string($_POST['pool']);
	$garage = mysql_real_escape_string($_POST['garage']);
	$garage_size = mysql_real_escape_string($_POST['garage_size']);
	$front_garden = mysql_real_escape_string($_POST['front_garden']);
	$rear_garden = mysql_real_escape_string($_POST['rear_garden']);
	$int_features = mysql_real_escape_string($_POST['int_features']);
	$ext_features = mysql_real_escape_string($_POST['ext_features']);
	$fees = mysql_real_escape_string($_POST['fees']);
	$tax = mysql_real_escape_string($_POST['tax']);
	$lastedit  = date("Y:m:d H:i:s");

	$sql = "UPDATE properties SET `status`='$status', `sale_type`='$sale_type', `category`='$category', `name`='$name', `address`='$address', `village`='$village', `lng`='$lng', `lat`='$lat', `department`='$department', `postcode`='$postcode', `last_edit`='$lastedit' WHERE `property_id`='$id'";
	if (mysql_query($sql))
	{
		$msg = "Congratulations, your property &lt;b&gt;".$name."&lt;/b&gt; is now complete. If you set your property status to Draft click &lt;a href=\"manage-edit.php?id=$id\"&gt;here&lt;/a&gt; to change it to Published!";
	}else{
		$msg = "We will make sure that your photos are added to your property asap.";
	}
}
?&gt;

&lt;?php
$sql = mysql_query("SELECT * FROM properties WHERE `property_id`='$id' AND `username`='{$session-&gt;username}'");
while($propertyRow = mysql_fetch_array($sql))
{
	$id = $propertyRow['property_id'];
	$status = $propertyRow['status'];
	$saletype = $propertyRow['sale_type'];
	$category = $propertyRow['category'];
	$name = $propertyRow['name'];
	$address = $propertyRow['address'];
	$village = $propertyRow['village'];
	$long = $propertyRow['long'];
	$lat = $propertyRow['lat'];
	$department = $propertyRow['department'];
	$postcode = $propertyRow['postcode'];
	$price = $propertyRow['price'];
	$lastedit = $propertyRow['last_edit'];
	$dateentered = $propertyRow['date_entered'];
	$sec = substr($propertyRow['date_entered'],17,2);
	$minute= substr($propertyRow['date_entered'],14,2);
	$hour = substr($propertyRow['date_entered'],11,2);
	$day = substr($propertyRow['date_entered'],8,2);
	$month = substr($propertyRow['date_entered'],5,2);
	$year = substr($propertyRow['date_entered'],0,4);
	$date_entered = $day."/".$month."/".$year." ".$hour.":".$minute.":".$sec;
}
?&gt;
&lt;form action="write-photos.php?mode=update&amp;?id=&lt;?php echo $id; ?&gt;" method="post" enctype="multipart/form-data" style="border:0px; padding:0px; margin:0px;"&gt;
	&lt;input name="MAX_FILE_SIZE" type="hidden" value="&lt;?php echo $MAXimagesize; ?&gt;" /&gt; &lt;!-- must proceed file input fields! --&gt;
	&lt;input name="name" type="hidden" value="&lt;?php echo $name; ?&gt;" /&gt;
	&lt;input name="last_edit" type="hidden" id="last_edit" value="&lt;?php echo $lastedit; ?&gt;" /&gt;
	&lt;div id="content"&gt;
		&lt;h2&gt;&lt;?php echo getLang('attachphotos'); ?&gt;&lt;/h2&gt;
		&lt;?php echo "&lt;h3&gt;".$msg."&lt;/h3&gt;"; ?&gt;
		&lt;div id="sidebar-left"&gt;
			&lt;ul id="post_options"&gt;
				&lt;li class="current"&gt;&lt;?php echo getLang('briefdetails'); ?&gt;&lt;/li&gt;
				&lt;li&gt;ID: &lt;?php echo $id; ?&gt;&lt;br&gt;&lt;?php echo getLang('name'); ?&gt;: &lt;?php echo $name; ?&gt;&lt;br&gt;&lt;?php echo getLang('department'); ?&gt;: &lt;?php echo $department; ?&gt;&lt;br&gt;&lt;?php echo getLang('price'); ?&gt; ?&lt;?php echo $price; ?&gt;&lt;br&gt;&lt;br&gt;&lt;?php echo getLang('dateposted'); ?&gt;: &lt;?php echo $dateentered; ?&gt;&lt;/li&gt;
				&lt;li class="finish"&gt;&lt;?php echo getLang('finishedadding'); ?&gt;&lt;/li&gt;
				&lt;li&gt;
					&lt;select id="post_status" name="status" onchange="if (this.selectedIndex==1){this.form['check'].style.visibility='visible'}else {this.form['check'].style.visibility='hidden'};"&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('no'); ?&gt;&lt;/option&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('yes'); ?&gt;&lt;/option&gt;
					&lt;/select&gt;
				&lt;/li&gt;
				&lt;li&gt;
					&lt;b&gt;&lt;font color="#0099FF"&gt;&lt;?php echo getLang('checkphotos'); ?&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;
					&lt;input type="checkbox" name="check" style="visibility:hidden;" onclick="this.form.Submit.disabled = !this.checked;"&gt;&lt;?php echo getLang('enablesave'); ?&gt;&lt;br&gt;&lt;br&gt;
					&lt;input class="save" name="Submit" type="submit" value="&lt;?php echo getLang('save'); ?&gt;" disabled="disabled"&gt;
				&lt;/li&gt;
				&lt;li class="related"&gt;&lt;b&gt;&lt;?php echo getLang('relatedlinks'); ?&gt;&lt;/b&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage.php"&gt;&lt;?php echo getLang('manageyourproperties'); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage-draft.php"&gt;&lt;?php echo getLang('viewyourdrafts'); ?&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/div&gt;

		&lt;div id="write-property"&gt;
			&lt;script type="text/javascript"&gt;
				/* This function is called when user selects file in file dialog */
				function checkext(upload_field)
				{
					var re_text = /\.jpeg|\.jpg/i;
					var filename = upload_field.value;
					/* Checking file type */
					if (filename.search(re_text) == -1)
					{
						alert("Please select a JPEG file.");
						upload_field.value = '';
					}
					return true;
				}
			&lt;/script&gt;
			&lt;table width="100%" border="0" cellpadding="0" cellspacing="4"&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo1'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[1]" type="file" id="photo[1]" title="&lt;?php echo getLang('fieldrequired'); ?&gt;" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo2'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[2]" type="file" id="photo[2]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo3'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[3]" type="file" id="photo[3]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo4'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[4]" type="file" id="photo[4]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo5'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[5]" type="file" id="photo[5]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo6'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[6]" type="file" id="photo[6]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo7'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[7]" type="file" id="photo[7]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo8'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[8]" type="file" id="photo[8]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo9'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[9]" type="file" id="photo[9]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo10'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[10]" type="file" id="photo[10]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo11'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[11]" type="file" id="photo[11]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo12'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[12]" type="file" id="photo[12]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/table&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/form&gt;

  • 0
try this code and see where we get. it's pretty hard to know for certain there are no problems with it because i can't actually run it. to run it i need all the rest of your code, structures of all your database tables, and sample data from all of your tables.

&lt;?php
if ( (isset($_GET['mode']) &amp;&amp; ($_GET['mode'] == "update") )
{

The code above, that starts at the begining of the entire code you gave me does not like this symbol '{' . So that needs fixing and could you also write a thumbnail function for me. I need these sizes for thumbnails but i want the filename to be the same as the original photos so, if you could get the uploading to generate a thumbnail for each photo for each size in there own folder that would be great. I have set out the directories below along with the sizes I need and they must be jpg only please.

Sizes:

50 x 50

75 x 80

100 x 100

170 x 170

Directories:

This is the main directory for the original photos to go into ../photos/properties/$session->username/$name/

The thumbnail photos for each size should go like this

50 x 50 ../photos/properties/$session->username/$name/50/

75 x 80 ../photos/properties/$session->username/$name/75/

100 x 100 ../photos/properties/$session->username/$name/100/

170 x 170 ../photos/properties/$session->username/$name/170/

The filenames should be the same so that the site can read the thumbnails.

So if original in ../photos/properties/$session->username/$name/$photo1 is photo1.jpg, then the filename should be the same in

../photos/properties/$session->username/$name/100/$photo1 as photo1.jpg for 100 x 100 thumbnails.

This would be a great help if you could include this for me. I would really appreciate it very much.

P.S. For some reason I can't update any information in my database but I can add or delete information from the database using a form. I have never had any problems with updating information before and I have spoken to my web host and they said there is nothing that they can do. I have checked my priviliges to see if I have permission to write on all and they are all ticked, so I don't know what could be wrong.

Do you think I should create a new database and re-insert my tables and see if that helps with the problem.

  • 0
The code above, that starts at the begining of the entire code you gave me does not like this symbol '{' . So that needs fixing

oops, there's a parenthesis missing, replace with

&lt;?php
if ( (isset($_GET['mode'])) &amp;&amp; ($_GET['mode'] == "update") )
{

and could you also write a thumbnail function for me

i'm afraid i have no experience of image manipulation with php, so i'm going to have to leave that for someone else unless i find the time to research it.

P.S. For some reason I can't update any information in my database but I can add or delete information from the database using a form. I have never had any problems with updating information before and I have spoken to my web host and they said there is nothing that they can do. I have checked my priviliges to see if I have permission to write on all and they are all ticked, so I don't know what could be wrong.

Do you think I should create a new database and re-insert my tables and see if that helps with the problem.

there could be any number of factors involved in your update query failing, from a broken query, to conflicts with other records due to unique columns, to permissions at row/column/table/database levels. with previous code of yours we added a check after each query, which if the query failed would print a message telling the user so, and also if in debug mode would display the error. you need to make sure you do this for all queries, you never know when one might fail! this will be able to tell you why your query is failing and will lead to an appropriate solution.

  • 0
oops, there's a parenthesis missing, replace with
&lt;?php
if ( (isset($_GET['mode'])) &amp;&amp; ($_GET['mode'] == "update") )
{

i'm afraid i have no experience of image manipulation with php, so i'm going to have to leave that for someone else unless i find the time to research it.

there could be any number of factors involved in your update query failing, from a broken query, to conflicts with other records due to unique columns, to permissions at row/column/table/database levels. with previous code of yours we added a check after each query, which if the query failed would print a message telling the user so, and also if in debug mode would display the error. you need to make sure you do this for all queries, you never know when one might fail! this will be able to tell you why your query is failing and will lead to an appropriate solution.

Ok your code works great, but it still won't update the database with the photos for the property. What do you think I should do? No errors show up but I do get uploaded successfully and the photos are in the uploaded directory.

I still get

Warning: mkdir(../photos/properties/username/name/) [function.mkdir]: File exists in /home/account/public_html/panel/write-photos.php on line 138

etc... for the other 11 photos uploaded. Why does it create 12 directories instead of 1?

  • 0

ok, make sure you're including those constants.php and lib.inc.php files you had before, and then try this copy

&lt;?php
if ( (isset($_GET['mode'])) &amp;&amp; ($_GET['mode'] == "update") )
{
	$id = $_GET['id'];
	$username = (isset($_POST['username'])) ? serialize($_POST['username']) : '';
	$int_features = (isset($_POST['int_features'])) ? serialize($_POST['int_features']) : '';
	$ext_features = (isset($_POST['ext_features'])) ? serialize($_POST['ext_features']) : '';

	///// Upload Photos /////
	$PHOTOS = array();
	$picname = str_replace(" ","_",$_POST['name']);
	mkdir("../photos/properties/{$session-&gt;username}/$name/",0777);
	foreach ($_FILES["photo"]["error"] as $key =&gt; $error)
	{
		if ($error == UPLOAD_ERR_OK)
		{
			$tmp_name = mysql_real_escape_string($_FILES["photo"]["tmp_name"][$key]);
			$photo = mysql_real_escape_string($_FILES["photo"]["name"][$key]);
			$photo = preg_replace("/([^a-z0-9])+/i", ".", $photo);
			move_uploaded_file($tmp_name, "../photos/properties/{$session-&gt;username}/$name/$photo");
			chmod("../photos/properties/{$session-&gt;username}/$name/$photo", 0777);
			$picno = $key;
			$msg = "Photo ".$picno." ".$photo." uploaded.&lt;br /&gt;";
			$PHOTO[$picno] = $photo;
		} else {
			$msg = "Photo number $key failed to upload!&lt;br /&gt;";
		}
	}

	$PHOTOS_SQL = array();
	foreach ($PHOTOS as $key =&gt; $value)
	{
		$PHOTOS_SQL[] = "`photo{$key}`='{$value}'";
	}
	if (! empty($PHOTOS_SQL))
	{
		$PHOTOS_SQL = implode(', ', $PHOTOS_SQL);
		$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL} WHERE `property_id`='$id'";
		if(mysql_query($sqlphotos) === false)
		{
			$msg = "There was an error adding uploaded photos to the property, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
			echo sqlError(__FILE__, __LINE);
		}else{
			$msg = "Successfully added uploaded photos to this property!&lt;br&gt;";
		}
	} else {
		$msg = "No uploaded photos to attach to the property!";
	}

	///// Update Property to DB /////
	$newname = str_replace(" ","_",$photo);
	$status = mysql_real_escape_string($_POST['status']);
	$sale_type = mysql_real_escape_string($_POST['sale_type']);
	$category = mysql_real_escape_string($_POST['category']);
	$name = addslashes(mysql_real_escape_string($_POST['name']));
	$address = mysql_real_escape_string($_POST['address']);
	$village = mysql_real_escape_string($_POST['village']);
	$lng = mysql_real_escape_string($_POST['lng']);
	$lat = mysql_real_escape_string($_POST['lat']);
	$department = mysql_real_escape_string($_POST['department']);
	$postcode = mysql_real_escape_string($_POST['postcode']);
	$description_fr = addslashes(mysql_real_escape_string($_POST['description_fr']));
	$description_en = addslashes(mysql_real_escape_string($_POST['description_en']));
	$price = mysql_real_escape_string($_POST['price']);
	$bedrooms = mysql_real_escape_string($_POST['bedrooms']);
	$bathrooms = $_POST['bathrooms'];
	$view = mysql_real_escape_string($_POST['view']);
	$meters = mysql_real_escape_string($_POST['meters']);
	$terrain = mysql_real_escape_string($_POST['terrain']);
	$pool = mysql_real_escape_string($_POST['pool']);
	$garage = mysql_real_escape_string($_POST['garage']);
	$garage_size = mysql_real_escape_string($_POST['garage_size']);
	$front_garden = mysql_real_escape_string($_POST['front_garden']);
	$rear_garden = mysql_real_escape_string($_POST['rear_garden']);
	$int_features = mysql_real_escape_string($_POST['int_features']);
	$ext_features = mysql_real_escape_string($_POST['ext_features']);
	$fees = mysql_real_escape_string($_POST['fees']);
	$tax = mysql_real_escape_string($_POST['tax']);
	$lastedit  = date("Y:m:d H:i:s");

	$sql = "UPDATE properties SET `status`='$status', `sale_type`='$sale_type', `category`='$category', `name`='$name', `address`='$address', `village`='$village', `lng`='$lng', `lat`='$lat', `department`='$department', `postcode`='$postcode', `last_edit`='$lastedit' WHERE `property_id`='$id'";
	if (mysql_query($sql) === false)
	{
		$msg = "Error occured updating property data.";
		echo sqlError(__FILE__, __LINE);
	}else{
		$msg = "Congratulations, your property &lt;b&gt;".$name."&lt;/b&gt; is now complete. If you set your property status to Draft click &lt;a href=\"manage-edit.php?id=$id\"&gt;here&lt;/a&gt; to change it to Published!";
	}
}
?&gt;

&lt;?php
$sql = mysql_query("SELECT * FROM properties WHERE `property_id`='$id' AND `username`='{$session-&gt;username}'");
$result = mysql_query($sql);
if ($result === false)
{
	$msg = "Error occured fetching data.";
	echo sqlError(__FILE__, __LINE);
}
while($propertyRow = mysql_fetch_array($sql))
{
	$id = $propertyRow['property_id'];
	$status = $propertyRow['status'];
	$saletype = $propertyRow['sale_type'];
	$category = $propertyRow['category'];
	$name = $propertyRow['name'];
	$address = $propertyRow['address'];
	$village = $propertyRow['village'];
	$long = $propertyRow['long'];
	$lat = $propertyRow['lat'];
	$department = $propertyRow['department'];
	$postcode = $propertyRow['postcode'];
	$price = $propertyRow['price'];
	$lastedit = $propertyRow['last_edit'];
	$dateentered = $propertyRow['date_entered'];
	$sec = substr($propertyRow['date_entered'],17,2);
	$minute= substr($propertyRow['date_entered'],14,2);
	$hour = substr($propertyRow['date_entered'],11,2);
	$day = substr($propertyRow['date_entered'],8,2);
	$month = substr($propertyRow['date_entered'],5,2);
	$year = substr($propertyRow['date_entered'],0,4);
	$date_entered = $day."/".$month."/".$year." ".$hour.":".$minute.":".$sec;
}
?&gt;
&lt;form action="write-photos.php?mode=update&amp;?id=&lt;?php echo $id; ?&gt;" method="post" enctype="multipart/form-data" style="border:0px; padding:0px; margin:0px;"&gt;
	&lt;input name="MAX_FILE_SIZE" type="hidden" value="&lt;?php echo $MAXimagesize; ?&gt;" /&gt; &lt;!-- must proceed file input fields! --&gt;
	&lt;input name="name" type="hidden" value="&lt;?php echo $name; ?&gt;" /&gt;
	&lt;input name="last_edit" type="hidden" id="last_edit" value="&lt;?php echo $lastedit; ?&gt;" /&gt;
	&lt;div id="content"&gt;
		&lt;h2&gt;&lt;?php echo getLang('attachphotos'); ?&gt;&lt;/h2&gt;
		&lt;?php echo "&lt;h3&gt;".$msg."&lt;/h3&gt;"; ?&gt;
		&lt;div id="sidebar-left"&gt;
			&lt;ul id="post_options"&gt;
				&lt;li class="current"&gt;&lt;?php echo getLang('briefdetails'); ?&gt;&lt;/li&gt;
				&lt;li&gt;ID: &lt;?php echo $id; ?&gt;&lt;br&gt;&lt;?php echo getLang('name'); ?&gt;: &lt;?php echo $name; ?&gt;&lt;br&gt;&lt;?php echo getLang('department'); ?&gt;: &lt;?php echo $department; ?&gt;&lt;br&gt;&lt;?php echo getLang('price'); ?&gt; ?&lt;?php echo $price; ?&gt;&lt;br&gt;&lt;br&gt;&lt;?php echo getLang('dateposted'); ?&gt;: &lt;?php echo $dateentered; ?&gt;&lt;/li&gt;
				&lt;li class="finish"&gt;&lt;?php echo getLang('finishedadding'); ?&gt;&lt;/li&gt;
				&lt;li&gt;
					&lt;select id="post_status" name="status" onchange="if (this.selectedIndex==1){this.form['check'].style.visibility='visible'}else {this.form['check'].style.visibility='hidden'};"&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('no'); ?&gt;&lt;/option&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('yes'); ?&gt;&lt;/option&gt;
					&lt;/select&gt;
				&lt;/li&gt;
				&lt;li&gt;
					&lt;b&gt;&lt;font color="#0099FF"&gt;&lt;?php echo getLang('checkphotos'); ?&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;
					&lt;input type="checkbox" name="check" style="visibility:hidden;" onclick="this.form.Submit.disabled = !this.checked;"&gt;&lt;?php echo getLang('enablesave'); ?&gt;&lt;br&gt;&lt;br&gt;
					&lt;input class="save" name="Submit" type="submit" value="&lt;?php echo getLang('save'); ?&gt;" disabled="disabled"&gt;
				&lt;/li&gt;
				&lt;li class="related"&gt;&lt;b&gt;&lt;?php echo getLang('relatedlinks'); ?&gt;&lt;/b&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage.php"&gt;&lt;?php echo getLang('manageyourproperties'); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage-draft.php"&gt;&lt;?php echo getLang('viewyourdrafts'); ?&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/div&gt;

		&lt;div id="write-property"&gt;
			&lt;script type="text/javascript"&gt;
				/* This function is called when user selects file in file dialog */
				function checkext(upload_field)
				{
					var re_text = /\.jpeg|\.jpg/i;
					var filename = upload_field.value;
					/* Checking file type */
					if (filename.search(re_text) == -1)
					{
						alert("Please select a JPEG file.");
						upload_field.value = '';
					}
					return true;
				}
			&lt;/script&gt;
			&lt;table width="100%" border="0" cellpadding="0" cellspacing="4"&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo1'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[1]" type="file" id="photo[1]" title="&lt;?php echo getLang('fieldrequired'); ?&gt;" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo2'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[2]" type="file" id="photo[2]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo3'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[3]" type="file" id="photo[3]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo4'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[4]" type="file" id="photo[4]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo5'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[5]" type="file" id="photo[5]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo6'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[6]" type="file" id="photo[6]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo7'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[7]" type="file" id="photo[7]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo8'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[8]" type="file" id="photo[8]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo9'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[9]" type="file" id="photo[9]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo10'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[10]" type="file" id="photo[10]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo11'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[11]" type="file" id="photo[11]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo12'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[12]" type="file" id="photo[12]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/table&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/form&gt;

Edited by Anaron
  • 0
ok, make sure you're including those constants.php and lib.inc.php files you had before, and then try this copy

The mkdir is fixed so thank you for that.

Ok I did what you said by including those files. Now on this other tweak you did for me.

if ($result === false)
{
	$msg = "Error occured fetching data.";
	echo sqlError(__FILE__, __LINE);
}

This shows up before pressing the submit button to update the photos. Is that an error it's self because the data must be fetched as I can see the property details in the brief section and the rest is in the background so why does it say 'Error occured fetching data.' ?

P.S. Database will still not update, maybe that is related to what I'm asking.

  • 0

oops, i noticed a couple of bugs, new copy:

&lt;?php
if ( (isset($_GET['mode'])) &amp;&amp; ($_GET['mode'] == "update") )
{
	$id = $_GET['id'];
	$username = (isset($_POST['username'])) ? serialize($_POST['username']) : '';
	$int_features = (isset($_POST['int_features'])) ? serialize($_POST['int_features']) : '';
	$ext_features = (isset($_POST['ext_features'])) ? serialize($_POST['ext_features']) : '';

	///// Upload Photos /////
	$PHOTOS = array();
	$picname = str_replace(" ","_",$_POST['name']);
	if (! is_dir("../photos/properties/{$session-&gt;username}/$name/")) { mkdir("../photos/properties/{$session-&gt;username}/$name/",0777); }
	foreach ($_FILES["photo"]["error"] as $key =&gt; $error)
	{
		if ($error == UPLOAD_ERR_OK)
		{
			$tmp_name = mysql_real_escape_string($_FILES["photo"]["tmp_name"][$key]);
			$photo = mysql_real_escape_string($_FILES["photo"]["name"][$key]);
			$photo = preg_replace("/([^a-z0-9])+/i", ".", $photo);
			move_uploaded_file($tmp_name, "../photos/properties/{$session-&gt;username}/$name/$photo");
			chmod("../photos/properties/{$session-&gt;username}/$name/$photo", 0777);
			$picno = $key;
			$msg = "Photo ".$picno." ".$photo." uploaded.&lt;br /&gt;";
			$PHOTO[$picno] = $photo;
		} else {
			$msg = "Photo number $key failed to upload!&lt;br /&gt;";
		}
	}

	$PHOTOS_SQL = array();
	foreach ($PHOTOS as $key =&gt; $value)
	{
		$PHOTOS_SQL[] = "`photo{$key}`='{$value}'";
	}
	if (! empty($PHOTOS_SQL))
	{
		$PHOTOS_SQL = implode(', ', $PHOTOS_SQL);
		$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL} WHERE `property_id`='$id'";
		if(mysql_query($sqlphotos) === false)
		{
			$msg = "There was an error adding uploaded photos to the property, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
			echo sqlError(__FILE__, __LINE__);
		}else{
			$msg = "Successfully added uploaded photos to this property!&lt;br&gt;";
		}
	} else {
		$msg = "No uploaded photos to attach to the property!";
	}

	///// Update Property to DB /////
	$newname = str_replace(" ","_",$photo);
	$status = mysql_real_escape_string($_POST['status']);
	$sale_type = mysql_real_escape_string($_POST['sale_type']);
	$category = mysql_real_escape_string($_POST['category']);
	$name = addslashes(mysql_real_escape_string($_POST['name']));
	$address = mysql_real_escape_string($_POST['address']);
	$village = mysql_real_escape_string($_POST['village']);
	$lng = mysql_real_escape_string($_POST['lng']);
	$lat = mysql_real_escape_string($_POST['lat']);
	$department = mysql_real_escape_string($_POST['department']);
	$postcode = mysql_real_escape_string($_POST['postcode']);
	$description_fr = addslashes(mysql_real_escape_string($_POST['description_fr']));
	$description_en = addslashes(mysql_real_escape_string($_POST['description_en']));
	$price = mysql_real_escape_string($_POST['price']);
	$bedrooms = mysql_real_escape_string($_POST['bedrooms']);
	$bathrooms = $_POST['bathrooms'];
	$view = mysql_real_escape_string($_POST['view']);
	$meters = mysql_real_escape_string($_POST['meters']);
	$terrain = mysql_real_escape_string($_POST['terrain']);
	$pool = mysql_real_escape_string($_POST['pool']);
	$garage = mysql_real_escape_string($_POST['garage']);
	$garage_size = mysql_real_escape_string($_POST['garage_size']);
	$front_garden = mysql_real_escape_string($_POST['front_garden']);
	$rear_garden = mysql_real_escape_string($_POST['rear_garden']);
	$int_features = mysql_real_escape_string($_POST['int_features']);
	$ext_features = mysql_real_escape_string($_POST['ext_features']);
	$fees = mysql_real_escape_string($_POST['fees']);
	$tax = mysql_real_escape_string($_POST['tax']);
	$lastedit  = date("Y:m:d H:i:s");

	$sql = "UPDATE properties SET `status`='$status', `sale_type`='$sale_type', `category`='$category', `name`='$name', `address`='$address', `village`='$village', `lng`='$lng', `lat`='$lat', `department`='$department', `postcode`='$postcode', `last_edit`='$lastedit' WHERE `property_id`='$id'";
	if (mysql_query($sql) === false)
	{
		$msg = "Error occured updating property data.";
		echo sqlError(__FILE__, __LINE__);
	}else{
		$msg = "Congratulations, your property &lt;b&gt;".$name."&lt;/b&gt; is now complete. If you set your property status to Draft click &lt;a href=\"manage-edit.php?id=$id\"&gt;here&lt;/a&gt; to change it to Published!";
	}
}
?&gt;

&lt;?php
$sql = "SELECT * FROM properties WHERE `property_id`='$id' AND `username`='{$session-&gt;username}'";
$result = mysql_query($sql);
if ($result === false)
{
	$msg = "Error occured fetching data.";
	echo sqlError(__FILE__, __LINE__);
}
while($propertyRow = mysql_fetch_array($sql))
{
	$id = $propertyRow['property_id'];
	$status = $propertyRow['status'];
	$saletype = $propertyRow['sale_type'];
	$category = $propertyRow['category'];
	$name = $propertyRow['name'];
	$address = $propertyRow['address'];
	$village = $propertyRow['village'];
	$long = $propertyRow['long'];
	$lat = $propertyRow['lat'];
	$department = $propertyRow['department'];
	$postcode = $propertyRow['postcode'];
	$price = $propertyRow['price'];
	$lastedit = $propertyRow['last_edit'];
	$dateentered = $propertyRow['date_entered'];
	$sec = substr($propertyRow['date_entered'],17,2);
	$minute= substr($propertyRow['date_entered'],14,2);
	$hour = substr($propertyRow['date_entered'],11,2);
	$day = substr($propertyRow['date_entered'],8,2);
	$month = substr($propertyRow['date_entered'],5,2);
	$year = substr($propertyRow['date_entered'],0,4);
	$date_entered = $day."/".$month."/".$year." ".$hour.":".$minute.":".$sec;
}
?&gt;
&lt;form action="write-photos.php?mode=update&amp;?id=&lt;?php echo $id; ?&gt;" method="post" enctype="multipart/form-data" style="border:0px; padding:0px; margin:0px;"&gt;
	&lt;input name="MAX_FILE_SIZE" type="hidden" value="&lt;?php echo $MAXimagesize; ?&gt;" /&gt; &lt;!-- must proceed file input fields! --&gt;
	&lt;input name="name" type="hidden" value="&lt;?php echo $name; ?&gt;" /&gt;
	&lt;input name="last_edit" type="hidden" id="last_edit" value="&lt;?php echo $lastedit; ?&gt;" /&gt;
	&lt;div id="content"&gt;
		&lt;h2&gt;&lt;?php echo getLang('attachphotos'); ?&gt;&lt;/h2&gt;
		&lt;?php echo "&lt;h3&gt;".$msg."&lt;/h3&gt;"; ?&gt;
		&lt;div id="sidebar-left"&gt;
			&lt;ul id="post_options"&gt;
				&lt;li class="current"&gt;&lt;?php echo getLang('briefdetails'); ?&gt;&lt;/li&gt;
				&lt;li&gt;ID: &lt;?php echo $id; ?&gt;&lt;br&gt;&lt;?php echo getLang('name'); ?&gt;: &lt;?php echo $name; ?&gt;&lt;br&gt;&lt;?php echo getLang('department'); ?&gt;: &lt;?php echo $department; ?&gt;&lt;br&gt;&lt;?php echo getLang('price'); ?&gt; ?&lt;?php echo $price; ?&gt;&lt;br&gt;&lt;br&gt;&lt;?php echo getLang('dateposted'); ?&gt;: &lt;?php echo $dateentered; ?&gt;&lt;/li&gt;
				&lt;li class="finish"&gt;&lt;?php echo getLang('finishedadding'); ?&gt;&lt;/li&gt;
				&lt;li&gt;
					&lt;select id="post_status" name="status" onchange="if (this.selectedIndex==1){this.form['check'].style.visibility='visible'}else {this.form['check'].style.visibility='hidden'};"&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('no'); ?&gt;&lt;/option&gt;
						&lt;option value=""&gt;&lt;?php echo getLang('yes'); ?&gt;&lt;/option&gt;
					&lt;/select&gt;
				&lt;/li&gt;
				&lt;li&gt;
					&lt;b&gt;&lt;font color="#0099FF"&gt;&lt;?php echo getLang('checkphotos'); ?&gt;&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;
					&lt;input type="checkbox" name="check" style="visibility:hidden;" onclick="this.form.Submit.disabled = !this.checked;"&gt;&lt;?php echo getLang('enablesave'); ?&gt;&lt;br&gt;&lt;br&gt;
					&lt;input class="save" name="Submit" type="submit" value="&lt;?php echo getLang('save'); ?&gt;" disabled="disabled"&gt;
				&lt;/li&gt;
				&lt;li class="related"&gt;&lt;b&gt;&lt;?php echo getLang('relatedlinks'); ?&gt;&lt;/b&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage.php"&gt;&lt;?php echo getLang('manageyourproperties'); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href="manage-draft.php"&gt;&lt;?php echo getLang('viewyourdrafts'); ?&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/div&gt;

		&lt;div id="write-property"&gt;
			&lt;script type="text/javascript"&gt;
				/* This function is called when user selects file in file dialog */
				function checkext(upload_field)
				{
					var re_text = /\.jpeg|\.jpg/i;
					var filename = upload_field.value;
					/* Checking file type */
					if (filename.search(re_text) == -1)
					{
						alert("Please select a JPEG file.");
						upload_field.value = '';
					}
					return true;
				}
			&lt;/script&gt;
			&lt;table width="100%" border="0" cellpadding="0" cellspacing="4"&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo1'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[1]" type="file" id="photo[1]" title="&lt;?php echo getLang('fieldrequired'); ?&gt;" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo2'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[2]" type="file" id="photo[2]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo3'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[3]" type="file" id="photo[3]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo4'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[4]" type="file" id="photo[4]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo5'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[5]" type="file" id="photo[5]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo6'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[6]" type="file" id="photo[6]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo7'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[7]" type="file" id="photo[7]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo8'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[8]" type="file" id="photo[8]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo9'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[9]" type="file" id="photo[9]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo10'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[10]" type="file" id="photo[10]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo11'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[11]" type="file" id="photo[11]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
				&lt;tr&gt;
					&lt;td&gt;&lt;?php echo getLang('photo12'); ?&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input name="photo[12]" type="file" id="photo[12]" size="30" onChange="return checkext(this)" /&gt;&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/table&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/form&gt;

it's harder to write code without bugs when you can't actually run it :/

edit: fixed another couple of bugs :rofl:

Edited by Anaron
  • 0

}
while($propertyRow = mysql_fetch_array($sql))
{

This for some reason is causing this error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mamaiso1/public_html/worldwide/france/panel/write-photos4.php on line 207

Also the new code does not fetch the data at all except the ID number now that is proberly because of this error.

  • 0
ooh, another bug, change $sql in that line to $result

Ok I made a few changes by removing some of the stuff that is no longer needed. I have also managed to get the last edit to work. So I know the update function is now working, so no I need to fix the part that tells the database the photo file for each photo because that is still not working. I am also wondering why all the messages don't show when the form is processed. It only seems to show the last one. Each message begins with $msg. I have uploaded the entire page to you so that you can see the code properly.

I have placed the code that is still causing problems.

$PHOTOS_SQL = array();
	foreach ($PHOTOS as $key =&gt; $photo)
	{
		$picno = $key;
		$PHOTOS_SQL[] = "`photo{$key}`='{$photo}'";
	}
	if (! empty($PHOTOS_SQL))
	{
		$PHOTOS_SQL = implode(', ', $PHOTOS_SQL);
		$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL} `last_edit`='$lastedit' WHERE `property_id`='$id'";
		if(mysql_query($sqlphotos) === false)
		{
			$msg = "There was an error adding uploaded photos to the property, please contact &lt;a href=\"mailto:[email protected]?subject=Uploading Photo Problem\"&gt;administrators&lt;/a&gt; for help!&lt;br&gt;";
			$msg = "No uploaded photos attached to the property!";
			echo sqlError(__FILE__, __LINE__);
		}else{
			$msg = "Successfully added uploaded photos to this property!&lt;br&gt;";
		}
}

This is the only thing that is holding me back from finishing the website so all of your help would be most appreciated.

write_photos5.php

  • 0

your messages aren't all showing because every time you set a message, you're overwriting the contents of $msg with the new message. you either need to echo out the messages rather than sticking them in a variable, or you need to concatenate the message to the string, e.g.

$msg = "first message";
$msg = $msg . "&lt;br /&gt;\n" . "second message"; //concatenate method 1
$msg .= "&lt;br /&gt;\n" . "third message"; //concatenate method 2

is the code above displaying an error? if so what?

i think there might be an error in the sql, replace

$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL} `last_edit`='$lastedit' WHERE `property_id`='$id'";

with

$sqlphotos = "UPDATE properties SET {$PHOTOS_SQL}, `last_edit`='$lastedit' WHERE `property_id`='$id'";

  • 0

Thank you guys for the previous help you have all given me on this topic. I would like to know why this topic is no longer under my account. All of my other previous topics are. Could an administrator or moderator check this out please. Thank you.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Save 78% on Microsoft Office 2024 Professional Plus: Lifetime License by Steven Parker Created with ChatGPT Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 78% on Microsoft Office 2024 Professional Plus: Lifetime License. The essentials to get it all done. Microsoft Office 2024 Home is the latest version of Microsoft’s renowned productivity suite, which includes essential applications like Word, Excel, PowerPoint, and OneNote. This version is specifically designed for individuals and families seeking reliable tools for various home tasks, including document creation, spreadsheet management, presentation design, and note-taking. Office 2024 Professional Plus is for students and families who want classic Office apps on their Mac or PC. A one-time purchase installed on 1 PC or Mac for use at home or school. Lifetime license One-time purchase installed on 1 Windows PC for use at home or work Instant Delivery & Download – access your software license keys and download links instantly Free customer service – only the best support! Microsoft Office 2024 Professional Plus includes: Microsoft Word Microsoft Excel Microsoft PowerPoint Microsoft Outlook Microsoft OneNote Microsoft Access Is it legit? Click here to verify Microsoft partnership No faffing about with subscriptions, just classic apps that don't expire. Good to Know ONE-TIME PURCHASE INSTALLED ON 1 DEVICE This licensing type will be connected with your Microsoft Account, NOT your actual device. This is a one-use code. The product you are purchasing is NOT MICROSOFT 365. Please read the product details. Redemption deadline: redeem your code within 30 days of purchase Access options: desktop Full versions No subscriptions – no monthly/annual fees Version: 2024 Updates included A Microsoft Office 2024 Professional Plus: Lifetime License normally costs $249.99, but this deal can be yours for just $54.97, that's a saving of $195. For full terms, specifications, and license info, click the link below. Microsoft Office 2024 Professional Plus for PC for $59.99 (was $249.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • Payday TWO!! Is 13 years old man I feel old - I remember trying it out and if I did not know I would say 5-6 years ago or something
    • Payday 2 engine upgrade adds 64-bit and DX11 support, drastically shrinks install size by Pulasthi Ariyasinghe Payday 2, the most popular entry in the heisting game franchise, is getting a surprising update after all these years. This is slated to be a complete engine upgrade that will enhance almost every aspect of the 13-year-old title, targeting performance, loading times, file size, rendering backend, and more. Developer Sidetrack Games is planning a beta to test out the new version ahead of the full public launch. The development team today revealed that the long-awaited upgrade to the 64-bit architecture is happening with this Diesel 3.0 engine update. By letting the game use more ram than 4GB, it is said to improve stability and compatibility on most hardware. It should also help modders in the long term with implementing larger changes too. "While many of the changes are made on the backend and not everything will be visible to you guys because it is a massive rewrite of the entire codebase, there will be a lot of things that you can look forward to," Sidetrack explained. Payday 2 will also hop over from DirectX 9 to 11. Instead of visual improvements, this is slated to reduce the amount of VRAM used by the title, letting more lower-end hardware access the title and run it better. Since these changes would require a complete redownload of the game anyway, Sidetrack says it has revamped "the game's packaging and bundling system." This should reduce the installation size from 86GB to 32GB. "So, now it's time to finally move the game to your SSDs," added the studio. The Payday 2 Diesel Engine 3.0 update is entering open beta on June 30 for Steam users. No console release plans were announced today. Sidetrack Games says it has been working on this complete rewrite of the codebase for the last nine months. While these changes should break most mods, the studio encouraged modders to use the beta period to repair their creations with support from the development team.
  • Recent Achievements

    • Week One Done
      Scoobystu earned a badge
      Week One Done
    • Week One Done
      tuben earned a badge
      Week One Done
    • First Post
      OffsetAbs earned a badge
      First Post
    • Reacting Well
      OffsetAbs earned a badge
      Reacting Well
    • First Post
      Kolakid60 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      439
    2. 2
      +Edouard
      197
    3. 3
      PsYcHoKiLLa
      156
    4. 4
      FloatingFatMan
      71
    5. 5
      Steven P.
      68
  • Tell a friend

    Love Neowin? Tell a friend!