advancedfuture Posted June 15, 2008 Share Posted June 15, 2008 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"); } } ?> Link to comment https://forums.phpfreaks.com/topic/110308-form-only-uploads-either-image-or-data-not-both/ Share on other sites More sharing options...
helraizer Posted June 15, 2008 Share Posted June 15, 2008 You'll need <form enctype="multipart/form-data"> in your form or else it won't upload the form. Link to comment https://forums.phpfreaks.com/topic/110308-form-only-uploads-either-image-or-data-not-both/#findComment-565960 Share on other sites More sharing options...
advancedfuture Posted June 15, 2008 Author Share Posted June 15, 2008 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> Link to comment https://forums.phpfreaks.com/topic/110308-form-only-uploads-either-image-or-data-not-both/#findComment-565963 Share on other sites More sharing options...
advancedfuture Posted June 15, 2008 Author Share Posted June 15, 2008 shameless bump.. Link to comment https://forums.phpfreaks.com/topic/110308-form-only-uploads-either-image-or-data-not-both/#findComment-565991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.