codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  image and form fieild upload problem  capoon at 22:39 on Sunday, April 25, 2010
 

Hi every one, i try to upload form data into database along with the image but the image name will be in my database as a link while the image itself will be in a directory. I have use something like this code before it works i think but the problem with this code is what i dont know.Is the problem from the directory where i want to store the image as was it keeps on returning the error below

-------Sorry, there was a problem uploading your file------


the code is ststed below
--------------------image.php------------------
[code]
<form enctype="multipart/form-data" action="/forum/addimage.html" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
[/code]

----------------addimage.php----------------------
[code]



<?php

//This is the directory where images will be saved
$target = "C:/Tomcat 6.0/webapps/fphp/image/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);

// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("student") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?> [/code]
the table is as follow

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo text);


please i need your help so that the code will work .if you have similar code that does the same thing i will appreciate .thanks for your help










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  converting JAVA code to JSP
•  image and form fieild upload problem
•  Multiplying currency
•  Java Garbage Collection Boot Camp
•  validations fo form fields
•  Setting page size at which scroll bars appear in browser window (javascript)
•  before executing a function
•  how to write a code in asp.net to create a glossary .
•  I am trying to run a programme which is using PGPLOT.When I call it from browser I get following error message.


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010