dlebowski Posted November 28, 2007 Share Posted November 28, 2007 I need some input on how to handle this situation. I have a form that is used to updated existing data in my database. One of the fields is an image. What is happening is that if I am happy with the image, but want to update other data, because I don't select an image from my file input field, it shows that I am updating a blank. Therefore when I submit my form update it changes my image field from something like "image.jpg" to " ". I have read that I cannot use "value" for a file input field. How would I make sure that the database entry for the image stays "image.jpg" instead of switching to " ". Thanks for having a look! <tr> <td valign=top style='background-color:<? echo $color ?>'> <? if ($LotImage6 == NULL) { ?> <img style='border-style: solid; border:1px solid #000000' src=/images/none.gif > <? } else { ?> <img style='border-style: solid; border:1px solid #000000' width=100 height=75 src= images/<? echo $LotAuctionDate ?>/thumbs/<? echo $LotImage6 ?> > <? } ?> </td> </tr> <tr height=2px> <td> </td> </tr> <tr> <td><input type="file" name="image6" title="Click here to select the image you would like to feature with this auction"></td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td> <table width=980 cellpadding=0 cellspacing=0 > <tr height=4px> <td> </td> </tr> <tr align=left> <td><input style="color: blue; font-size: 9px; height: 20px;" type="submit" value ="Update Lot" name="submit1" alt="UPDATE LOT" title="Click here to update lot"></td></form> </tr> <tr height=5px> <td> </td> </tr> Quote Link to comment Share on other sites More sharing options...
s0c0 Posted November 28, 2007 Share Posted November 28, 2007 The simplest solution in PHP? Add a checkbox to your form. If the checkbox is checked it means you want to update the image, if not then you don't want to update the image. So when you sql update code receives the POST data if the checkbox value equals 1 or whatever you will embed a variable in the update syntax for your image inside the sql query, otherwise that variable equals nothing or ''. Make sense? There are better solutions to this, but if you are satisfied with this then congrats. EDIT The better solution is to check whether or not the $_FILES array contains anything. If it does not then don't update the image else update it. You would use the same variable type thing I noted above in your sql statement: if($_FILES['image6']['name']!='') { $imgUpdate = 'SET image = '.$whateverBlah; } else { $imgUpdate = ''; } $sql = "UPDATE someTable SET name='whatever your code is'".$imgUpdate." WHERE id=$id"; Quote Link to comment Share on other sites More sharing options...
dlebowski Posted November 28, 2007 Author Share Posted November 28, 2007 That makes total sense, but may be confusing to my users. What I probably will end up doing is having the image update a completely different form. That way if they only want to update information other than the image, the image won't be affected. They would have to update the image seperately. Thanks for the suggestion. Any other input on how I could do this with one form submission would be welcomed. Thanks again! Quote Link to comment Share on other sites More sharing options...
s0c0 Posted November 28, 2007 Share Posted November 28, 2007 i updated the original post, second solution is the one i would implement. Quote Link to comment Share on other sites More sharing options...
dlebowski Posted November 28, 2007 Author Share Posted November 28, 2007 I think that's going to do it man. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.