I'm doing a student system, and in the registration, i am not being able to insert the record of the student which also has an image to be uploaded. The new folder is being created however the record is not inserted and the file is not moved. I'm not quite sure what the problem is.
<?php
include_once ('Database.php');
$course = $_POST['course'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$filename = $_FILES['file']['name'];
$target_dir = mkdir("Images/".$username."/");
$target_file = $target_dir . basename($filename);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif");
$idquery ="SELECT `courseid` FROM `course` WHERE coursename = '$course'";
$result= mysqli_query($conn, $idquery);
if (mysqli_num_rows($result)==1){
while($row = mysqli_fetch_assoc($result)){
$courseid= ($row['courseid']);
}
}
$sql = "INSERT INTO student VALUES('$firstname','$lastname','$email','$username','$password', '$filename', '$courseid')";
if (mysqli_query($conn, $sql)){
header("Location: StudentDashboard.html");
}else{
echo "Registration failed";
}
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$filename);
}
?>