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

save_student.php


    if(ISSET($_POST['save'])){
            $student_id = $_POST['student_id'];
            $name = $_POST['name'];
            $password = md5($_POST['password']);
            $uploaddir = '../images/Profile_Images/';
            $image =$uploaddir . basename($_FILES['image']['name'].time());
            error_reporting(E_ALL);
            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>
                    <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>
                            <div class="form-group">
                                <label>Name</label>
                                <input type="text" name="name" class="form-control" required="required"/>
                            </div>
                            <div class="form-group">
                                <label>Password</label>
                                <input type="password" name="password" class="form-control" required="required"/>
                            </div>

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

                        </div>
                    </div>
                    <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>
                    </div>
                </form>
            </div>
        </div>
    </div>

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 *