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