'What might the issue with this my code to upload image in my users form

I created a form to capture user details including their passport, but when ever the user fill the form, it went blank without populating the database with the filled data, but the image will be moved to specified directory. How do correct the error so that the data and the image path will be populated into the database.

if(isset($_POST['submit']))
{
$name=$_POST['name'];
$image = $_FILES['image']['name'];
$regno=$_POST['regno']; 
$email=$_POST['email']; 
$password=$_POST['password'];
$status=1;
// image file directory
    $target = "images/".basename($image);

    move_uploaded_file($_FILES['image']['tmp_name'], $target);


$sql="INSERT INTO  tblstudents(name,image,regno,email,password,status) VALUES(:name,:image,:regno,:email,:password, :status)";

$query = $dbh->prepare($sql);
$query->bindParam(':name',$name,PDO::PARAM_STR);
$query->bindParam(':image',$_image,PDO::PARAM_STR);
$query->bindParam(':regno',$regno,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':password',$password,PDO::PARAM_STR);
$query->bindParam(':status',$status,PDO::PARAM_STR);

$query->execute();
$Id = $dbh->Id();
if($Id)
{
$msg="user added successfully";
}

elseif (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
        $msg = "Image uploaded successfully";
}else 
{
$error="Something went wrong. Please try again";
}

}
?>

Here is my html form

 <form class="form-horizontal" method="post" enctype="multipart/form-data">
                                                    <!-- image file  enctype="multipart/form-data" -->

<div class="form-group">
<label for="default" class="col-sm-2 control-label">Full Name</label>
<div class="col-sm-10">
<input type="text" name="name" class="form-control" id="name" required="required" autocomplete="off">
</div>
</div>



<div class="form-group">
<label for="default" class="col-sm-2 control-label">Registration Number</label>
<div class="col-sm-10">
<input type="text" name="regno" class="form-control" id="regno" maxlength="50" required="required" autocomplete="off">
</div>
</div>

<div class="form-group">
<label for="default" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-10">
<input type="email" name="email" class="form-control" id="email" required="required" autocomplete="off">
</div>
</div>


<div class="form-group">
<label for="default" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" name="password" class="form-control" id="password" required="required" autocomplete="off">
</div>
</div>



<!-- passport to upload -->

<div class="form-group">
<label for="default" class="col-sm-2 control-label">Upload Passport</label>
<div class="col-sm-10">
<input type="file" name="image" id="image">     
</div>      
</div>                               
                                                    <div class="form-group">
                                                        <div class="col-sm-offset-2 col-sm-10">
                                                            <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                                        </div>
                                                    </div>
                                                </form>


Solution 1:[1]

As $_image variable is not defined, shouldn't you use $target variable instead?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ?brahim Halil Çad?rc?