Page 1 of 1

[SOLVED] Picture upload form problem.

Posted: Wed Apr 29, 2009 4:21 pm
by ReX357
Hi. I'm having trouble with this script. It doesn't throw an error of any kind. But it 'echoes' nothing back either. Nothing is uploaded and nothing is created in the database. Help!

Code: Select all

<?php
 
//Connect to the database here
 
require_once ('connect.php');
 
$file_upload="true";
$file_up_size=$_FILES[Picture][size];
 
if (!($_FILES[Picture][type] =="image/jpeg" OR $_FILES[Picture][type] =="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";}
 
$file_name=$_FILES[Picture][name];
 
$add="../personnel/$file_name"; // the path with the file name where the file will be stored, upload is the directory name. 
 
if($file_upload=="true"){
 
if(move_uploaded_file ($_FILES['Picture'][tmp_name], $add)){
 
mysql_query("INSERT INTO personnel (memberName, memberPicture, memberDescription) VALUES('$_POST[memberName]', '$_FILES[Pictures][name]', '$_POST[memberDescription]')")
or die(mysql_error());
 
echo '<p> The new team member has been successfully added to the database! <a href="cms_personnel.php">Click here</a> if you are not automaticly  redirected to the Personnel Database page in 5 seconds. </p>';
 
} else { echo '<p>Failed to upload file. Contact Site admin to fix the problem</p>'; }}
 
?>
My enctype is already setup to "multipart/form-data", all the tables exist with the fields (and names all match). Same for the name of the fields in the forms.

Re: Picture upload form problem.

Posted: Wed Apr 29, 2009 8:38 pm
by ReX357
Sweet! That fixed my problem! Thank you very much sir.

Re: Picture upload form problem.

Posted: Wed Apr 29, 2009 8:44 pm
by ReX357
One more question. This is what I use to insert into my database:

$file_name=$_FILES['Picture']['name'];

mysql_query("INSERT INTO personnel (memberName, memberPicture, memberDescription) VALUES('$_POST[memberName]', '$file_name', '$_POST[memberDescription]')")

When I query the database for the filename of the picture, it returns %22the_name_of_the_picture%22. Why is that?

Re: Picture upload form problem.

Posted: Wed Apr 29, 2009 10:21 pm
by ReX357
Nevermind, I fixed my problem (it was in my html code :P)