Updxate field only if submittet!

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
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Updxate field only if submittet!

Post by jmansa »

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:

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>
The update script:

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();

}
Hope somebody can help...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_POST['image'] should not exist (in a meaningful sense.) $_FILES['image'] would instead. You can check the metadata given by the uploading system in the $_FILES array.
Post Reply