karimali1337's avatar

Undefined Array Key "image"

When i'm uploading image in my form it gives me Undefined Array Key "image" i'm giving it the EncType and right name but i don't know where is the problem

MySQL insert code

if ($_SERVER['REQUEST_METHOD'] == "POST") {
  if (isset($_POST['send'])) {
    $First_Name = $_POST['First_Name'];
    $Last_Name = $_POST['Last_Name'];
    $Email = $_POST['Email'];
    $Phone = $_POST['Phone'];
    $Password = sha1($_POST['Password']);
    $country = $_POST['country'];
     $image = $_POST['image'];

    if (isset($_POST['image'])) {
      $imageName = $_FILES['image']['name'];
      $imageType = $_FILES['image']['type'];
      $imageTmp = $_FILES['image']['tmp_name'];
      move_uploaded_file($imageTmp, "images/", $image);
    }
    $sql = "INSERT INTO users(first_name,last_name,email,phone,password,country,image) VALUES ('$First_Name','$Last_Name','$Email','$Phone','$Password','$country','$image')";
  }
}

HTML Code

  <form method="POST" action="index.php" enctype="multipart/form-data">
      
           <div class="form-group">
        <label for="exampleInputPassword2">image</label>
        <input type="file" class="form-control" id="exampleInputPassword2" name="image">
      </div>


    </form>
0 likes
5 replies
sr57's avatar

@karimali1337

You forgot the submit in the form

<input type="submit" value="Upload Image" name="image">
karimali1337's avatar

@sr57 i've done it in the full form,i'm only adding the image input because the form is so large

MichalOravec's avatar
Level 75

$_POST['image'] doesn't exist only $_FILES['image']

karimali1337's avatar

@MichalOravec Thank you its working now,But the image don't move to the folder,It's saved to the DB but not moved to images folder.

Please or to participate in this conversation.