2013-06-04 2 views
0

Всякий раз, когда я пытаюсь загрузить файл с помощью формы и иметь его вставить файл в MySQL, я получаю эти errors-пытается загрузить изображение и его обновить MySQL

Примечание: Undefined индекс: файл в /home/sgas/public_html/x/agentpage.php на линии 300

Примечание: Undefined индекс: файл в /home/sgas/public_html/x/agentpage.php на линии 305

Примечание: Undefined индекс : файл в /home/sgas/public_html/x/agentpage.php в строке 310

Я просмотрел эти имена, и они кажутся правильными, поэтому я понятия не имею, что не так прямо сейчас: /.

Вот код, начинающийся с формы, где вы загружаете изображение.

<td align="right" valign="top" class="bodymaintextalt">applicable document</td> 
<td> 
    <input name="file" type="file" id="file" size="35"> 
    </tr> 
    <tr> 
     <td align="right" valign="top" class="bodymaintextalt">received</td> 
     <td> 
      <input name="received" type="text" id="received" value="$"> 
     </td> 
    </tr> 
    <tr> 
     <td align="right" valign="top" class="bodymaintextalt">paid</td> 
     <td> 
      <input name="paid" type="text" id="paid" value="$"> 
     </td> 
    </tr> 
    <tr> 
     <td align="right" valign="top">&nbsp;</td> 
     <td> 
      <div align="right"> 
       <input type="submit" name="Submit32" value="Submit"> 


<?php 
ini_set('display_errors',1); 
ini_set('display_startup_errors',1); 
error_reporting(-1); 
if ('POST' === $_SERVER['REQUEST_METHOD']){ 
    $con = mysql_connect("localhost","xxx","xxxxx"); 

    if (!$con){ 
     die('Could not connect: ' . mysql_error()); 
    } 

    mysql_select_db("xxxxx", $con); 

    $target = "clientdoc/"; 
    $target = $target . basename($_FILES['file']['agentclient']); 

    $date = $_POST['date']; 
    $propertydescription = $_POST['propertydescription']; 
    $transactiontype = $_POST['transactiontype']; 
    $applicabledocument = ($_FILES['file']['agentclient']); 
    $received = $_POST['received']; 
    $paid = $_POST['paid']; 

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

     //Tells you if its all ok 
     echo "The file ". basename($_FILES['uploadedfile']['agentclient']). " 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."; 
    } 

    $sql = mysql_query("INSERT INTO `transactions` (`date`, `agentclient`, `propertydescription`, `transactiontype`, `applicabledocument`, `received`, `paid`) 
    VALUES ('$date', '$agentclient', '$propertydescription', '$transactiontype', '$applicabledocument', '$received', '$paid')") or die(mysql_error()); 

    $query = mysql_query($sql); 
    if ($_SERVER['REQUEST_METHOD'] === 'POST'){ 
     echo "Succesfully added transaction. Updating table..."; 
     echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"48\">"; 
     mysql_close($con); 
    } 
} 
+0

у вас есть 'ENCTYPE = "многослойные/форма-данные"' в ''

тега? – Sean

+0

Я думаю, что у U нет пользователя 'enctype =" multipart/form-data "' –

+0

Я сделал это и теперь Im получаю эти ошибки –

ответ

0

ваше имя файл файл так, чтобы изменить его agentclient так

<input type="file" name="agentclient" id="file"/> 

$target = $target . basename($_FILES['agentclient']['name']); 
+0

Это неверно/неверно. Если вы измените его на 'type =" file "name =" agentclient ", то это будет' $ _FILES ['agentclient'] 'NOT' $ _FILES ['file'] ['agentclient'] 'http: // www .php.net/ручной/EN/features.file-upload.post-method.php – Sean

Смежные вопросы