Updxate field only if submittet!
Posted: Thu Nov 01, 2007 4:58 am
I am trying to make an update upload form, but I have 1 problem. For each image I can submit a url for banner link, but here is my problem. If I only want to change the url and let the image be, it changes the image to nothing! How do I tell the db to let the record for the image stand and only update the url? Here is what I have done!
The form:
The update script:
Hope somebody can help...
The form:
Code: Select all
<form name="upload" method="post" enctype="multipart/form-data" action="">
<input type="text" name="url" id="url" value="<? echo ''.$url.''; ?>"><br>
<input name="id" type="hidden" value="<? echo ''.$id.''; ?>"><input name="image" type="file"><br>
<input name="Submit" type="submit">
</form>Code: Select all
$url=$_POST['url'];
$image=$_POST['image'];
$id=$_POST['id'];
if ($_POST['image'])
{
$query="UPDATE uploads SET url='$url', image='$image' WHERE id='$id'";
mysql_query($query);
if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}
echo "Succes...";
mysql_close();
}
else
{
$query="UPDATE uploads SET url='$url' WHERE id='$id'";
mysql_query($query);
if(!mysql_query($query)){
print "Error Occurred:". mysql_error() ;
exit();
}
echo "Succes...";
mysql_close();
}