0

I get this error when I put in my image upload code. Everything works without it. I have re written this many times and search high and low but I still get :Notice: Undefined index: file_img in C:\wamp\www\HW2_Submissions\movieSub.php on line 12 When I separate the two into there own things images, and creatmovie pieces they work fine on their own. The snippet I have given you is the body area of the HTML, there is a menu, head, connection, and footer php file separated out and the connection houses the DB info. Please help thank you.

<?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>
Rico
  • 59
  • 2
  • 9

1 Answers1

1

You need enctype='multipart/form-data' to upload file:

<form action="movie-add.php" enctype="multipart/form-data" method="post" style="padding-top: 220px">
Đào Minh Hạt
  • 2,742
  • 16
  • 20
  • @Daominhat thanks I appreciate it I swear I tried this before. But irregardless it works now. Thanks – Rico Mar 07 '17 at 08:33