[SOLVED] Picture upload form problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ReX357
Forum Newbie
Posts: 4
Joined: Wed Apr 29, 2009 4:18 pm

[SOLVED] Picture upload form problem.

Post 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.
Last edited by ReX357 on Wed Apr 29, 2009 10:22 pm, edited 2 times in total.
ReX357
Forum Newbie
Posts: 4
Joined: Wed Apr 29, 2009 4:18 pm

Re: Picture upload form problem.

Post by ReX357 »

Sweet! That fixed my problem! Thank you very much sir.
ReX357
Forum Newbie
Posts: 4
Joined: Wed Apr 29, 2009 4:18 pm

Re: Picture upload form problem.

Post 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?
ReX357
Forum Newbie
Posts: 4
Joined: Wed Apr 29, 2009 4:18 pm

Re: Picture upload form problem.

Post by ReX357 »

Nevermind, I fixed my problem (it was in my html code :P)
Post Reply