我的 php 代码有问题。我正在尝试使用表单将数据写入 mysql。该表单还包含一个视频上传,它将视频存储在本地并将视频的 url 存储到数据库中。问题是当我测试它时,它会出现多个“videoname”、“videoupload”、“videodescription”的未定义索引错误。有趣的是,如果我没有选择要上传的文件并且仍然在其他字段中输入内容,它会将信息写入数据库并且不会出现错误。所以这与视频有关。有人知道它可能是什么吗?谢谢!表格代码:
<form action="videoUpload.php" id="videoUp" method='POST' enctype="multipart/form-data">
<p>Name:<textarea name="videoname" value="" class="name" ></textarea></p>
<p>Upload video:<input type="hidden" name="MAX_FILE_SIZE" value="10485760"> <input type="file" name="videoupload"> </p>
<p>Video Description:<textarea name="videodescription" value="" class="step" ></textarea></p>
<p><input type="submit" name="videosubmit" value="Submit Video" class="submit" /></p>
</form>
和 php:
<?php
session_start();
//This is the directory where images will be saved
$target = "assets/video/";
$target = $target . basename( $_FILES['videoupload']['name']);
$name = $_POST['videoname'];
$description = $_POST['videodescription'];
$connect = mysql_connect("localhost","root","") or die("Couldn't connect");
mysql_select_db("fyp") or die("Couldn't find db");
$queryreg = mysql_query("INSERT INTO videos(VideoName,VideoLocation,VideoDescription) VALUES('$name','$target','$description')");
//Writes the photo to the server
if(move_uploaded_file($_FILES['videoupload']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file 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.";
}
?>