Hi everyone. Thanks in advance for helping. I'm having a problem with some of my code. I have a form, that uploads a file to my server and inserts the file name into a table. The users can go in to an edit form and modify other info and re-upload a new file. The problem is when the user does not upload a new file, the value in the table(for that file) gets blanked out. I tried solving this by passing a hidden field with the old image name, but that didn't work.
So basically I want this:
if no file to upload...don't blank it out.
if there is a file...upload it and change the record in the table.
Here is my processing code:
if($_POST['img1'] == "") {
$_POST['img1'] = $_POST['oldimg1'];
$image1 = $_POST['oldimg1'];
}
if($_POST['img2'] == "") {
$_POST['img2'] = $_POST['oldimg2'];
$image2 = $_POST['oldimg2'];
}
if($_POST['img3] == "") {
$_POST['img3'] = $_POST['oldimg3'];
$image3 = $_POST['oldimg3'];
}
if($_POST['img4'] == "") {
$_POST['img4'] = $_POST['oldimg4'];
$image4 = $_POST['oldimg4'];
}
$target = "../ads/";
$target = $target . basename( $_FILES['img1']['name']) ;
$image1 = basename( $_FILES['img1']['name']) ;
if(move_uploaded_file($_FILES['img1']['tmp_name'], $target));
$target2 = "../ads/";
$target2 = $target2 . basename( $_FILES['img2']['name']) ;
$image2 = basename( $_FILES['img2']['name']) ;
if(move_uploaded_file($_FILES['img2']['tmp_name'], $target));
$target3 = "../ads/";
$target3 = $target3 . basename( $_FILES['img3']['name']) ;
$image3 = basename( $_FILES['img3']['name']) ;
if(move_uploaded_file($_FILES['img3']['tmp_name'], $target));
$target4 = "../ads/";
$target4 = $target4 . basename( $_FILES['img4']['name']) ;
$image4 = basename( $_FILES['img4']['name']) ;
if(move_uploaded_file($_FILES['img4']['tmp_name'], $target));
$updateSQL = sprintf("UPDATE ports SET location=%s, address=%s, city=%s, `state`=%s, zip=%s, lake=%s, website=%s, lat=%s, lon=%s, googlelat=%s, googlelon=%s, portstatus=%s, img1=%s, img2=%s, img3=%s, img4=%s, url1=%s, url2=%s, url3=%s, url4=%s WHERE id=%s",
GetSQLValueString($_POST['location'], "text"),
GetSQLValueString($_POST['address'], "text"),
GetSQLValueString($_POST['city'], "text"),
GetSQLValueString($_POST['state'], "text"),
GetSQLValueString($_POST['zip'], "text"),
GetSQLValueString($_POST['lake'], "text"),
GetSQLValueString($_POST['website'], "text"),
GetSQLValueString($_POST['lat'], "text"),
GetSQLValueString($_POST['lon'], "text"),
GetSQLValueString($_POST['googlelat'], "text"),
GetSQLValueString($_POST['googlelon'], "text"),
GetSQLValueString($_POST['portstatus'], "text"),
GetSQLValueString($image1, "text"),
GetSQLValueString($image2, "text"),
GetSQLValueString($image3, "text"),
GetSQLValueString($image4, "text"),
GetSQLValueString($_POST['url1'], "text"),
GetSQLValueString($_POST['url2'], "text"),
GetSQLValueString($_POST['url3'], "text"),
GetSQLValueString($_POST['url4'], "text"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_air2access, $air2access);
$Result1 = mysql_query($updateSQL, $air2access) or die(mysql_error());