0

每当我尝试使用表单上传文件并将文件插入 mysql 时,我都会收到这些错误-

注意:未定义的索引:文件在 /home/sgas/public_html/x/agentpage.php 的第 300 行

注意:未定义索引:文件在 /home/sgas/public_html/x/agentpage.php 的第 305 行

注意:未定义的索引:文件在 /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);
    }
}
4

1 回答 1

0

你的文件名是 file 所以把它改成 agentclient 所以

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

$target = $target . basename( $_FILES['agentclient']['name']);
于 2013-06-04T04:53:15.880 回答