imarockstar Posted September 24, 2009 Share Posted September 24, 2009 I ahve a little script that uploads a file ... here is the code ... it works .. but i need it to skip over the updating of the image name if there was no file uploaded ... everything works great, but if no image is uploaded it ofcourse puts nothing in the DB which causes the image to display as nothing is there ... all my variables are above this code in the file .. but i wont waste time typing them ... if ($_POST['updatemerch']) { $newname = uniqid("whc").".jpg"; move_uploaded_file($_FILES['mimage']['tmp_name'], "../images/merch/$newname"); $mimage = $newname; mysql_query("UPDATE merch SET userid = '$userid', bid = '$bid', mcat = '$mcat', mname = '$mname', mquantity = '$mquantity', msmall = '$msmall', mmedium = '$mmedium', mlarge = '$mlarge' , mcost = '$mcost', mprice = '$mprice', mdesc = '$mdesc', mimage = '$mimage' WHERE mid = '$mid' "); header("Location: ../view_merch.php"); } Link to comment https://forums.phpfreaks.com/topic/175390-file-upload-help/ Share on other sites More sharing options...
MatthewJ Posted September 24, 2009 Share Posted September 24, 2009 but i wont waste time typing them ... You should try copy and paste... I hear it is pretty awesome How about right before your query you do something like if($mimage == "") { $mimage = 'defaultimage.jpg'; } so it inserts whatever you want? Link to comment https://forums.phpfreaks.com/topic/175390-file-upload-help/#findComment-924392 Share on other sites More sharing options...
mikesta707 Posted September 24, 2009 Share Posted September 24, 2009 if (move_uploaded_file($_FILES['mimage']['tmp_name'], "../images/merch/$newname")){ $mimage = $newname; mysql_query("UPDATE merch SET userid = '$userid', bid = '$bid', mcat = '$mcat', mname = '$mname', mquantity = '$mquantity', msmall = '$msmall', mmedium = '$mmedium', mlarge = '$mlarge' , mcost = '$mcost', mprice = '$mprice', mdesc = '$mdesc', mimage = '$mimage' WHERE mid = '$mid' "); header("Location: ../view_merch.php"); } Link to comment https://forums.phpfreaks.com/topic/175390-file-upload-help/#findComment-924393 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.