Jump to content

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.