0
我的PHP代码有问题。我正在尝试使用表单将数据写入mysql。该表单还包含视频上传以及在本地存储视频并将视频的网址存储到数据库中。问题是,当我测试它时,会出现'videoname','videoupload','videodescription'的未定义索引的多个错误。有趣的是,如果我没有选择一个文件上传,并仍然在其他领域输入的东西,它将信息写入数据库,并没有出现错误。所以这与视频有关。有人知道它会是什么吗?谢谢! 代码形式:使用PHP存储视频时未定义的索引错误
<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.";
}
?>
尝试和sanitze插入它们之前的变量,可能是一些charatar那里,混淆查询。 –
你有“form”和“php脚本”在同一页'videoUpload.php' – mgraph
你收到了什么错误代码?检查'$ _FILES ['videoupload'] ['error']'并与http://www.php.net/manual/en/features.file-upload.errors.php – CodeZombie