1

I'm getting this error Undefined index: image and i already applied some suggestions from the internet which is to check if the file is empty and to match the name that has been used inside the input type.

and here's what my code looks like

form

<form accept-charset="UTF-8" method="POST" 
action="../includes/user-management/signup.inc.php" 
enctype="multipart/form-data" class="form" id="myform">

input type="file"

<p class="form-field ">
<label class="field-label" style="text-align:center";>Upload an Image</label><p></p>
   <input type="file" id="myFile" name="image" accept="image/*" size="30" required></p>

script

<script type="text/javascript">
 $(document).ready(function(){
$('#myform').validate({
    rules: {
      email: {
        required: true,
        email: true
      },
      password: {
        required: true,
        minlength: 8
      }       
    },
    // Specify validation error messages
    messages: {
      password: {
        required: "Please provide a password",
        minlength: "Your password must be at least 8 characters long"
      }
    },
     submitHandler: subform
  });
    function subform(){
            var data = $("#myform").serialize();
            $.ajax({
                type: 'POST',
                url: '../includes/user-management/signup.inc.php',
                data: data,
                beforeSend: function(){
                    $("#info").fadeOut();
                    $("#submit").html("Signing-up...");
                },
                success: function(resp){
                    if(resp=="success"){
                        $("#submit").html("<img src='ajax-loader.gif' width='15'/> &nbsp; Signing-up");
                        setTimeout('window.location.href = "../index.php";',4000);
                    } else{
                        $("#info").fadeIn(1000, function(){
                            $("#info").html("<div class='text-danger'>"+resp+"</div>");
                            $("#submit").html('Sign-up');
                        })
                    }
                }
            })
        }   
  });

</script>

signup.inc.php(incomplete copy, I just revealed where i applied the $_FILES['image']['name'])

<?php
session_start();
if (isset($_POST['_utf8']) && !empty($_FILES['image'])) {

include_once '../connection/dbh.inc.php';
echo "i'm in";
$firstName = trim(mysqli_real_escape_string($conn, $_POST['firstName']));
$lastName = trim(mysqli_real_escape_string($conn, $_POST['lastName']));
$email = trim(mysqli_real_escape_string($conn, $_POST['email']));
$password = trim(mysqli_real_escape_string($conn, $_POST['password']));
$businessPermit = basename($_FILES['image']['name']);

} else {
echo "error";
 echo "<pre>". var_dump($_FILES['image']) . "</pre>";
exit();
}

the var_dump displays NULL btw Thanks in advance !

0 Answers0