Database record id & image problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnew
Forum Newbie
Posts: 18
Joined: Tue Oct 12, 2004 7:40 am

Database record id & image problem

Post by phpnew »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello every body
I have this problem in my admin panel it is a estate agents website where I am not able to edit the property. It is not taking recognising the id of the record and the image is not getting stored in pictures folder. same problem with delete as well.

Please help

Code: Select all

<?php require("stuff.php");
require("validate_user.php");

$property_edited = false;

if (isset($_POST['submit'])) {
$edit_property = $_POST['edit_property'];
$property_type = $_POST['property_type'];
$contract = $_POST['contract'];
$bedrooms = $_POST['bedrooms'];
$property_details = $_POST['property_details'];
$property_value = $_POST['property_value'];
$area = $_POST['area'];
$id = $_POST['id'];
if (isset($edit_property) && ($edit_property == "validated")) 
$property_details = trim($property_details);
$property_value = trim($property_value);
if (is_numeric($property_value)) {
$db_connection = db_connect();
$query = "UPDATE houses SET property_type='$property_type', contract='$contract', bedrooms='$bedrooms', 

details='$property_details', value='$property_value', area='$area' WHERE id='$id'";
db_query($query, $db_connection);

if (is_uploaded_file($property_image)) {
// there was a file uploaded with the product
$image_properties = getimagesize($property_image);
if ($image_properties[2] == 2) {
// the file was a valid image
$image_width = $image_properties[0];
$image_height = $image_properties[1];
$new_width = 175;
if ($image_width > $new_width) {
// the image is too big, so we must resize it
$ratio = $new_width / $image_width;
$new_height = $image_height*$ratio;

$image = ImageCreateFromJPEG($property_image);
$new_image = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResized($new_image,$image,0,0,0,0,$new_width,$new_height,$image_width ,$image_height);
ImageJPEG($new_image, $property_image);
}
$image_name = "C:\Program Files\Apache Group\Apache\htdocs\pictures\property_".$id.".jpg";
copy($property_image, $image_name);
}
}

db_disconnect($db_connection);
$property_edited = true;
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<title>admin panel</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<meta name="KeyWords" content="" />
<meta name="Description" content="" />
<meta name="robots" content="index,follow" />

<link rel="stylesheet" type="text/css" href="../style.css" />

<script language="JavaScript" type="text/javascript">
<!--
//-->
</script>
</head>

<body>
<h2>Edit property :: User = <?php echo $_SESSION["valid_user"]." (".ucfirst($_SESSION["branch_name"]).")"; ?></h2>
<p align="center"><a href="menu.php"><- Main menu</a> - <a href="logout.php">Log off -></a></p>
<?php
if ($property_edited) {
echo "<p>The property was successfully modified</p>";
} else {
$db_connection = db_connect();
$query = "SELECT * FROM houses WHERE id='$id'";
$result = db_query($query, $db_connection);
$property = mysql_fetch_object($result);
db_disconnect($db_connection);
?>
<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="edit_property" value="validated" />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<table width="600" align="center">
<tr>
<td width="200"><p>Property type:</p></td>
<td width="400"><?php if ($edit_property == "validated") show_property_type($property_type); else 

show_property_type($property->property_type); ?></td>
</tr>
<tr>
<td width="200"><p>Contract:</p></td>
<td width="400"><select name="contract"><option value="let" <?php if (isset($contract) && ($contract == "let")) echo 

"selected"; elseif ($property->contract == "let") echo "selected"; ?>>Let</option><option value="sell" <?php if 

(isset($contract) && ($contract == "sell")) echo "selected"; elseif ($property->contract == "sell") echo "selected"; 

?>>Sell</option></select></td>
</tr>
<tr>
<td width="200"><p>Bedrooms:</p></td>
<td width="400"><?php if ($edit_property == "validated") show_bedrooms($bedrooms); else 

show_bedrooms($property->bedrooms); ?></td>
</tr>
<tr>
<td width="200"><p>Property details:</p></td>
<td width="400"><textarea name="property_details" rows="4" cols="35"><?php if (isset($property_details)) echo 

$property_details; else echo $property->details; ?></textarea></td>
</tr>
<tr>
<td width="200"><p>Property value:</p></td>
<td width="400"><input type="text" name="property_value" value="<?php echo $property->value; ?>" size="10" /></td>
</tr>
<tr>
<td width="200"><p>Area:</p></td>
<td width="400"><?php show_areas($property->area); ?></td>
</tr>
<tr>
<td width="200"><p>Picture:</p></td>
<td width="400"><input type="file" name="property_image" /></td>
</tr>
<tr>
<td width="600" colspan="2" align="center"><input type="submit" name="submit" value="Make changes" /></td>
</tr>
</table>
</form>
<?php } ?>
</body>
</html>

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Do some self tests on the code. What happens when you try to echo the id to the page? Is it the correct one? Then start off by just changing one field in the database to see if that is causing errors, and then add the others to it when its working correctly. Do you have write access to the picture folder? etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use the

Code: Select all

tags damnit.[/b][/color]

which part of the code isn't recognizing the id being posted? Maybe you aren't getting to this page correctly...
Post Reply