Jump to content

Form only uploads either image or data, not both!


advancedfuture

Recommended Posts

So I have this form, you upload an image, and some data with the form... problem is you can only either upload the image and no data... or you can upload the data and no image... it wont do both at the same time... I don't know what exactly is wrong, hope you fellow PHPers can help shed some light on whats wrong here!

 

Thanks

 

<?php
include "dbconnect.php";
if($_POST['submit'])
{
$price0 = $_POST['price0'];
$price1 = $_POST['price1'];
$price2 = $_POST['price2'];
$price3 = $_POST['price3'];
$name = $_POST['name'];
$description = $_POST['description'];
$city = $_POST['city'];
$state = $_POST['state'];
$unitId = md5(rand(1, time()));

//copy the file to the directory
$target_path = "upload/";

$_FILES['ufile']['name'] = md5(rand(1, time())).".jpg"; //renames the file
$target_path = $target_path . basename( $_FILES['ufile']['name'] ); 

if(move_uploaded_file($_FILES['ufile']['tmp_name'], $target_path)) {
    	echo "The file ".  basename( $_FILES['ufile']['name'] )." has been uploaded";
} 
else{
    	echo "There was an error uploading the file, please try again!";
	header( "Refresh: 3; upload.php");
}
$sourcefile = $_FILES['ufile']['name'];

// insert form data and image name into database
$query = "INSERT INTO units ( price0, price1, price2, price3, name, description, city, state, unitId, imgURL) VALUES('$price0','$price1','$price2','$price3','$name','$description','$city','$state','$unitId', '$sourcefile')";

$results = mysql_query($query);
if($results)
{
	echo "Upload of unit successful, upload another please!";
	header( "Refresh: 3; upload.php");
}
}	
?>

that is already set on my form. here is the form.

 

<form enctype="multipart/form-data" method="post" action="">
  <p>
   <label>Picture Upload
    <input name="ufile" type="file" id="ufile" size="50" />
    </label>
  </p>
    <label>price0
      <input type="text" name="price0" />
    </label>
  <p>
    <label>price1
    <input type="text" name="price1" />
    </label>
  </p>
  <p>
    <label>price2
    <input type="text" name="price2" />
    </label>
  </p>
  <p>
    <label>price3
    <input type="text" name="price3" />
    </label>
  </p>
  <p>
    <label>Name
    <input type="text" name="name" />
    </label>
  </p>
  <p>
    <label>description
    <textarea name="description"></textarea>
    </label>
</p>
  <p>
    <label>state
    <input type="text" name="state" />
    </label>
  </p>
  <p>
    <label>city
    <input type="text" name="city" />
    </label>
</p>
  <p>
    <label>
    <input type="submit" name="submit" value="submit" />
    </label>
  </p>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.