Pls i'm having issues inserting my form into the database. Each time i run the code, the error i get is
Warning: Undefined array key "course_image" in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 154
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 154
Warning: Undefined array key "course_video" in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 155
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 155
Warning: Undefined array key "course_image" in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 159
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 159
Warning: Undefined array key "course_video" in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 163
Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\netadem\admin\apps\insert.php on line 163
this is my form
<input type="hidden" name="instructor_id" value="<?=$id?>">
<div class="row mb-3">
<label for="inputNanme4" class="form-label"><strong>Course Title</strong></label>
<div class="col-sm-10">
<input type="text" name="course_title" class="form-control" id="inputNanme4">
</div>
</div>
<div class="row mb-3">
<label for="floatingTextarea" class="col-sm-2 col-form-label"><strong>Short Description</strong></label>
<div class="form-floating">
<textarea class="form-control" name="course_description" placeholder="Address" id="floatingTextarea" style="height: 100px; padding: 10px;"></textarea>
</div>
</div><br>
<div class="row mb-3">
<label class="form-label"><strong>Course Image</strong></label>
<div class="col-sm-10">
<input type="file" name="course_image" class="form-control" id="formFile">
</div>
</div><br>
<div class="row mb-3">
<label class="form-label"><strong>Course Video</strong></label>
<div class="col-sm-10">
<input type="file" name="course_video" class="form-control" id="formFile">
</div>
</div><br>
<!-- Quill Editor Full -->
<p><strong>Course Details </strong>(As much as possible, describe what this course is all about.)</p>
<div class="form-floating">
<textarea class="form-control" name="course_details" id="floatingTextarea" style="height: 250px; padding: 10px;"></textarea>
</div><br><br>
<!-- End Quill Editor Full -->
<a href="my-courses.php" class="btn btn-danger float-start m-2">Back</a>
<button type="submit" name="create-course" class="btn btn-primary float-start m-2">Submit</button>
here's my php insert logic code
if (isset($_POST['create-course']))
{
$img_folder = "../uploads/images/";
$videos_folder = "../uploads/videos/";
if(!file_exists($img_folder))
{
mkdir($img_folder,0777,true);
file_put_contents($img_folder."index.php", "<?php //silence");
file_put_contents("../uploads/index.php", "<?php //silence");
}
elseif(!file_exists($videos_folder))
{
mkdir($videos_folder,0777,true);
file_put_contents($videos_folder."index.php", "<?php //silence");
}
$current_time = time();
$instructor_id = $_POST['instructor_id'];
$course_title = mysqli_real_escape_string($connect, htmlentities($_POST['course_title']));
$course_description = mysqli_real_escape_string($connect, htmlentities($_POST['course_description']));
$course_details = mysqli_real_escape_string($connect, htmlentities($_POST['course_details']));
$course_image = $current_time.$_FILES['course_image']['name']; (Line 154)
$course_video = $current_time.$_FILES['course_video']['name']; (line 155)
//validate image
$image_allowed = ['image/jpeg','image/jpg','image/png'];
$img_type = $_FILES['course_image']['type']; (Line 159)
//validate video
$video_allowed = ['video/mp4','video/avi','video/3gp','video/mov','video/mpeg'];
$video_type = $_FILES['course_video']['type']; (Line 163)
$check_image = in_array($img_type, $image_allowed);
$check_video = in_array($video_type, $video_allowed);
if($check_image) // check file extension
{
if ($check_video)
{
$query = "INSERT INTO courses (user_id,course_title,course_description,course_details,course_image,course_video) VALUES ('$instructor_id','$course_title','$course_description','$course_details','$course_image','$course_video')";
$query_run = mysqli_query($connect, $query);
if ($query_run)
{
$img_tmp = $_FILES['course_image']['tmp_name'];
$destination = $img_folder.$current_time.$_FILES['course_image']['name'];
move_uploaded_file($img_tmp, $destination);
$video_tmp = $_FILES['course_video']['tmp_name'];
$vid_dst = $videos_folder.$current_time.$_FILES['course_image']['name'];
move_uploaded_file($img_tmp, $vid_dst);
$_SESSION['success'] = "Data Inserted Successfully.";
redirect('../my-courses.php');
}
else
{
$_SESSION['error'] = "Operation failed!";
redirect('../courses-add.php');
}
}
elseif(!$check_video)
{
$_SESSION['vid_error'] = "Only videos of type .mp4, .avi, .3gp, .mov, .mpeg are allowed.";
redirect('../courses-add.php');
}
}
elseif(!$check_image)
{
$_SESSION['img_error'] = "Only images of type .jpg, .jpeg, .png are allowed.";
redirect('../courses-add.php');
}
}
I'll glad if anyone can tell me why, my code isn't running.