2013-06-04 69 views
0

每當我嘗試使用表單上傳文件,並把它插入的文件到MySQL,我得到這些錯誤 -試圖上傳圖片,並將它MySQL的更新

公告:未定義的索引:文件中 在線路300 /home/sgas/public_html/x/agentpage.php

說明:未定義指數:文件中 /home/sgas/public_html/x/agentpage.php上線305

說明:未定義指數:文件在 /home/sgas/public_html/x/agentpage.php on line 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 = 「的multipart/form-data的」'在''

標籤? – Sean

+0

我想你沒有用戶'enctype =「multipart/form-data」' –

+0

我做到了,現在我得到這些錯誤 –

回答

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