I am creating a script that modifys a record in my database.
This script is suppost to take updated data from a form and update my database. This script also uploads a photo if a change is made. The name of this photo is stored in the database. The problem I am having is that when The photo is not being updated, it replaces the name in the database with a blank entry, rather than leaving it unchanged. Please look at my script and see what I am doing wrong.
Thanks,
Justin
<?
//check for required form variables
if ((!$POST[addr]) || (!$POST[city])) {
header("Location:http://www.lymantech.net/");
exit;
}
//set up table and database names
$db_name = "🙂";
$table_name = "main";
//connect to server and select database
$connection = @mysql_connect("localhost", "🙂", "🙂") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
// Uploading Files
if ($FILES[pic1] != "") {
$pic1name = $FILES[pic1][name];
@copy($FILES[pic1][tmp_name], "/var/www/html/secure/pics/" .$FILES[pic1][name]);
}
//build and issue query
$pic1_sql = "UPDATE $table_name SET
pic1 ='$pic1name'
WHERE id ='$_POST[id]'";
if ($_FILES[pic1] != "") {
$pic1_result = @($pic1_sql,$connection) or die(mysql_error());
}
//build and issue query
$sql = "UPDATE $table_name SET
addr ='$POST[addr]',
city ='$POST[city]',
state ='$POST[state]',
zip ='$POST[zip]',
cnty ='$POST[cnty]',
price ='$POST[price]',
bed ='$POST[bed]',
bath ='$POST[bath]',
sqft ='$POST[sqft]',
yrblt ='$POST[yrblt]',
acres ='$POST[acres]',
des ='$POST[des]',
sdes ='$POST[sdes]',
keyf ='$POST[keyf]'
WHERE id ='$_POST[id]'";
$result = @($sql,$connection) or die(mysql_error());
?>
<HTML>
<HEAD>
<TITLE>My Listing Management System:Listing Updated</TITLE>
</HEAD>
<BODY>
<h1>My Listing Management System</h1>
<h2><em>Modify a Listing -Listing Updated</em></h2>
<P>The following information was successfully updated</P>
<table cellspacing="3" cellpadding="3">
<tr>
<td width="459" valign="top">
<P><strong>ID:</strong>
<br>
<? echo "$_POST[id]"; ?></P>
<P><strong>Address:</strong>
<br>
<? echo "$_POST[addr]"; ?></P>
<P><strong>City:</strong>
<br>
<? echo "$_POST[city]"; ?></P>
<P><strong>State:</strong>
<br>
<? echo "$_POST[state]"; ?></P>
<P><strong>Zip Code:</strong>
<br>
<? echo "$_POST[zip]"; ?></P>
<P><strong>County:</strong>
<br>
<? echo "$_POST[cnty]"; ?></P>
<P><strong>Price:</strong>
<br>
<? echo "$_POST[price]"; ?></P>
<P><strong>Bedrooms:</strong>
<br>
<? echo "$_POST[bed]"; ?></P>
<P><strong>Bathrooms:</strong>
<br>
<? echo "$_POST[bath]"; ?></P>
<P><strong>Square Feet:</strong>
<br>
<? echo "$_POST[sqft]"; ?></P>
<P><strong>Year Built:</strong>
<br>
<? echo "$_POST[yrblt]"; ?></P>
<P><strong>Acreage:</strong>
<br>
<? echo "$_POST[acres]"; ?></P>
<P><strong>Detailed Description:</strong>
<br>
<? echo "$_POST[des]"; ?></P>
<P><strong>Short Description:</strong>
<br>
<? echo "$_POST[sdes]"; ?></P>
<P><strong>Key Features:</strong>
<br>
<? echo "$_POST[keyf]"; ?></P>
<P><strong>Picture #1:</strong>
<? echo "$pic1name"; ?>
<br>
</P>
</td>
</tr>
</table>
</BODY>
</HTML>