Maurice Botha
Maurice Botha

Reputation: 125

Uploading of files and saving

back again

So I have moved the code around a bit and now only get the unsuccessfull message. Please tell me where and what I am doing wrong.

My form on the editemployee.php page

<h1>Warnings</h1>
<div class="article" style="width:535px">
 <form enctype="multipart/form-data" action="includes/add.php" method="POST"> 
 <table>
  <tr>
  <td>Warning letter:</td>
  <td> <input type="file" name="warning1"></td>
  </tr>
   <tr>
  <td>Warning letter:</td>
  <td><input type="file" name="warning2"></td>
  </tr>
   <tr>
  <td>Warning letter Final:</td>
  <td><input type="file" name="warning3"></td>
  </tr>
   <tr>
  <td></td>
  <td><input type="submit" value="Add"> </td>
  </tr>
  </table>

 </form>

 </div>

An now I have move the processing code as suggested to its own file called add.php

<?php 
  //This is the directory where images will be saved 
$target = "files/empdocs"; 
$target1 = $target . basename( $_FILES['warning1']['name']); 
$target2 = $target . basename( $_FILES['warning2']['name']);
$target3 = $target . basename( $_FILES['warning3']['name']);

 //This gets all the other information from the form 

 $warning1=($_FILES['warning1']['name']); 
 $warning2=($_FILES['warning2']['name']);
 $warning3=($_FILES['warning3']['name']); 

 // Connects to your Database 
 mysql_connect("localhost", "username", "password") or die(mysql_error()) ; 
 mysql_select_db("database") or die(mysql_error()) ; 

  //Writes the information to the database 
 mysql_query("INSERT INTO ref_employees VALUES ('$warning1', '$warning2', '$warning3')") ;
  //Writes the file to the server 
if (move_uploaded_file($_FILES['warning1']['tmp_name'], $target1)
&& move_uploaded_file($_FILES['warning2']['tmp_name'], $target2)
&& move_uploaded_file($_FILES['warning3']['tmp_name'], $target3)) {

 //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."; 
 } 
 ?>

Upvotes: 0

Views: 79

Answers (3)

A. Zalonis
A. Zalonis

Reputation: 1609

If you want use JQuery and PHP to upload multifiles with a nice UI you can check this link and try JQuery-File-Upload library. It is very nice libs.

I think it will helps you

the link is https://github.com/blueimp/jQuery-File-Upload

Upvotes: 0

Mateusz Lerczak
Mateusz Lerczak

Reputation: 56

There is no something like this:

if(move_uploaded_file($_FILES['warning1']['tmp_name'], $target))
if(move_uploaded_file($_FILES['warning2']['tmp_name'], $target))
if(move_uploaded_file($_FILES['warning3']['tmp_name'], $target))  {

You have to

if (move_uploaded_file($_FILES['warning1']['tmp_name'], $target1)
&& move_uploaded_file($_FILES['warning2']['tmp_name'], $target2)
&& move_uploaded_file($_FILES['warning3']['tmp_name'], $target3)) {

And target variable, not like this:

$target = "files/empdocs"; 
$target = $target . basename( $_FILES['warning1']['name']); 
$target = $target . basename( $_FILES['warning2']['name']);
$target = $target . basename( $_FILES['warning3']['name']);

But:

$target = "files/empdocs"; 
$target1 = $target . basename( $_FILES['warning1']['name']); 
$target2 = $target . basename( $_FILES['warning2']['name']);
$target2 = $target . basename( $_FILES['warning3']['name']);

Upvotes: 0

Adam
Adam

Reputation: 1371

You have:

mysql_query("INSERT INTO ref_employees VALUES ('$warning1', '$warning2', '$warningfinal') WHERE 'idnumber' = $idnumber") ; 

WHERE should not be in INSERT statement!

Upvotes: 1

Related Questions