gpt4 book ai didi

php - 尝试上传图像并让它更新mysql

转载 作者:行者123 更新时间:2023-11-30 01:35:48 25 4
gpt4 key购买 nike

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

Notice: Undefined index: file in /home/sgas/public_html/x/agentpage.php on line 300

Notice: Undefined index: file in /home/sgas/public_html/x/agentpage.php on line 305

Notice: Undefined index: file in /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);
}
}

最佳答案

你的文件名是file,所以将其更改为agentclient,所以

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

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

关于php - 尝试上传图像并让它更新mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16909480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com