I have a problem with my php code. I am trying to write data into mysql using a form. the form contains a video upload as well that stores the video locally and stores an url of the video into the database. The problem is when i m testing it it comes up with multiple errors of undefined index for videoname , videoupload , videodescription . the funny thing is that if i m not choosing a file to upload and still input something in the other fields it writes the info in the database and doesn t come up with errors. So it s something related to the video. Does anybody have an idea of what it could be? Thanks! Code for the form:
<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.";
}
?>