php – upload profile picture fail-ThrowExceptions

Exception or error:

I have problem with saving profile picture for registration. After fill in all the registration form, i got errors that said

Notice: Undefined index: image in D:\xampp\htdocs\e-bag\admin\save_student.php on line 9

Notice: Undefined index: image in D:\xampp\htdocs\e-bagr\admin\save_student.php on line 12
Upload failed

Warning: mysqli_error() expects exactly 1 parameter, 0 given in D:\xampp\htdocs\e-bag\admin\save_student.php on line 20


            $student_id = $_POST['student_id'];
            $name = $_POST['name'];
            $password = md5($_POST['password']);
            $uploaddir = '../images/Profile_Images/';
            $image =$uploaddir . basename($_FILES['image']['name'].time());
            echo "<p>";
            if (move_uploaded_file($_FILES['image']['name'], $image)) // upload user image

            else {
             echo "Upload failed";

            mysqli_query($conn, "INSERT INTO `student` VALUES('', '$student_id', '$name','$password','$image')") or die(mysqli_error());

            header('location: student.php');

html class

<div class="modal fade" id="form_modal" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <form method="POST" action="save_student.php">  
                    <div class="modal-header">
                        <h4 class="modal-title">Add Student</h4>
                    <div class="modal-body">
                        <div class="col-md-3"></div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Student ID</label>
                                <input type="number" name="student_id" class="form-control" required="required"/>
                            <div class="form-group">
                                <input type="text" name="name" class="form-control" required="required"/>
                            <div class="form-group">
                                <input type="password" name="password" class="form-control" required="required"/>

                            <div class="icon1">
                              <span class="fa fa-user"></span>
                              <input type="file" name="image" id="image" />

                    <div style="clear:both;"></div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
                        <button name="save" class="btn btn-success" ><span class="glyphicon glyphicon-save"></span> Save</button>

this is my actual form
enter image description here

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *