1 Replies - 445 Views - Last Post: 31 March 2014 - 01:47 AM Rate Topic: -----

#1 cirustus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 16-February 13

PHP File Upload Problem

Posted 30 March 2014 - 10:37 PM

Hi im having trouble with uploading files and storing them into my DB.
so far i can get the file to be uploaded into the directory i want but i cant get the info into the database eg.

ID 1 UID 0 image pic1.jpg

so here is my code so far any ideas would be appreciated and again thanks for any help

the form
<form enctype="multipart/form-data" action="addpic.php" method="POST"> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Upload"> 

the php

 //This is the directory where images will be saved 
 $target = "../../pics/"; 
 $target = $target . basename( $_FILES['photo']['name']); 
 //This gets all the other information from the form 

 $ID= 0; 
 //Writes the information to the database 
$query = <<<SQL
      INSERT INTO `images`
      VALUES (NULL, '$ID', '$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."; 

Is This A Good Question/Topic? 0
  • +

Replies To: PHP File Upload Problem

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4208
  • View blog
  • Posts: 13,283
  • Joined: 08-June 10

Re: PHP File Upload Problem

Posted 31 March 2014 - 01:47 AM

to save something in a DB you need to use one of PHP’s database extensions (e.g. PDO) to get the data into your DB.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1