身份不明的索引错误PHP

时间:2017-03-07 08:27:26

标签: php html mysql html5

当我输入图片上传代码时出现此错误。没有它,一切都有效。我已经写了很多次并且搜索高低但我仍然得到:注意:第12行的C:\ wamp \ www \ HW2_Submissions \ movieSub.php中的未定义索引:file_img当我将两者分成自己的图像时,和creatmovie件他们自己工作得很好。我给你的片段是HTML的正文区域,有一个分离出的菜单,头部,连接和页脚php文件,连接包含数据库信息。请帮忙谢谢。

<?php 



if (isset($_POST['add'])) {

 $name = $_POST['name']; 
 $email = $_POST['email']; 
 $movie = $_POST['movie']; 
 $director = $_POST['director']; 
 $lead = $_POST['lead'];
 $textArea = $_POST['textArea']; 

$filetmp = $_FILES["file_img"]["tmp_name"];
$filename = $_FILES["file_img"]["name"];
$filetype = $_FILES["file_img"]["type"];
$filepath = "images/".$filename;

$query = "INSERT INTO createmovie (movieID, userName, email, movieName, directorsName, lead, Info) VALUES 
  (NULL,'$name', '$email', '$movie', '$director', '$lead','$textArea'); INSERT INTO images (imageID, img_name, img_path, img_type) VALUES (NULL, '$filename','$filetype','$filepath')"; 
  mysqli_multi_query($conn, $query);



 //     $result = $conn->query($query);
//  if (!$result) die($conn->error); 

if (headers_sent()) {
    die("Redirect failed. Please click on this link: <a href='movies-list.php'>Movie List</a>");
}else{
    exit(header("Location: movies-lists.php"));
}
?>

<div class="clearfix colelem" id="u711-4"><!-- content -->
    <p>Welcome Please Submit Movie</p>
   </div>

<form action="movie-add.php" method="post" style="padding-top: 220px">
  <div class="form-group" >
    <label for="InputName1">Your Name</label>
    <input type="name" name="name" class="form-control" id="InputName1" aria-describedby="nameHelp" placeholder="Enter Name">
    <small id="nameHelp" class="form-text text-muted">We'll never share your information with anyone else.</small>
  </div>
  <div class="form-group">
    <label for="Inputemail1">Email</label>
    <input type="email" name="email" class="form-control" id="Inputemail1" placeholder="Email">
  </div>
  <div class="form-group" >
    <label for="InputMovie1">Movie Name</label>
    <input type="text" name="movie" class="form-control" id="InputMovie1" aria-describedby="movieHelp" placeholder="Movie Name">
    </div>
     <div class="form-group" >
    <label for="InputDirector1">Directors Name</label>
    <input type="text" name="director" class="form-control" id="InputDirector1" aria-describedby="directorHelp" placeholder="Director Name">
    </div>
     <div class="form-group" >
    <label for="InputLead1">Lead Actor/Actress</label>
    <input type="text" name="lead" class="form-control" id="InputLead1" aria-describedby="LeadHelp" placeholder="Lead Name">
    </div>
    <div class="form-group">
    <label for="Textarea">More Information</label>
    <textarea class="form-control" id="Textarea" name="textArea" rows="3"></textarea>
    </div>
    <div class="form-group">
        <input type="file" name="file_img" />
    </div>
  <button type="submit" name="add" class="btn btn-primary" >Submit</button>
</form>

1 个答案:

答案 0 :(得分:1)

您需要enctype='multipart/form-data'上传文件:

<form action="movie-add.php" enctype="multipart/form-data" method="post" style="padding-top: 220px">