0

anyone can help my task in school, i confused that.. the image cant store to database.

<form action="doOrder.php" method="post" enctype="multipart/form-data">

Category : T-SHIRT

Choose Size
<label for="sizes"><span>
<input type="radio" name="sizes" value="S" checked="checked"/>S
<input type="radio" name="sizes" value="M" />M
<input type="radio" name="sizes" value="L" />L
<input type="radio" name="sizes" value="XL" />XL
</span>
</label>

Fabric Type
<select name="fabric">
    <option value="Cotton Combed">Cotton Combed</option>
    <option value="Cotton Carded">Cotton Carded</option>
   <option value="Polyester / PE">Polyester / PE</option>
    </select>

Total
<input type="number" name="total" min="1" max="100">
<input type="file" name="imageUpload" id="imageUpload">
<input value="Submit" type="submit" name="submit">
</form>

and this the doOrder.php

<?php 
    require_once("connect.php");

    $nama_file = $_FILES['images']['name'];
    $sizes = $_POST['sizes'];
    $fabric = $_POST['fabric'];
    $total = $_POST['total'];

    move_uploaded_file($_FILES['images']['tmp_name'], "images/".$_FILES['images']['name']);


    $simpan = mysql_query("INSERT INTO pesanan(category, sizes, fabric, total,images) VALUES('T-SHIRT','$sizes','$fabric','$total','$nama_file')");

    echo "Your add has been submited....";

?>

the error is that

Notice: Undefined index: images on line 4 Notice: Undefined index: images in on line 9 Notice: Undefined index: images in on line 9

1
  • Your <input type="file"/> has name="imageUpload", why are you referring to it in PHP as $_FILES['images']? Commented Oct 13, 2017 at 6:08

3 Answers 3

1

The key images does not exist in the files array. imageUpload is what you passed as the name attribute from the html form. So that's what you access

$nama_file = $_FILES['imageUpload']['name'];//imageUpload

move_uploaded_file($_FILES['imageUpload']['tmp_name'], "images/".$_FILES['imageUpload']['name']);

Also please add validations to your file upload module. As it is Trojans and other harmful files can easily be uploaded

Sign up to request clarification or add additional context in comments.

Comments

1

You actually try to access the form-input with name "images" - it doesn't exist. In your form, the field is named as "imageUpload"

So change:

$nama_file = $_FILES['images']['name'];

To:

$nama_file = $_FILES['imageUpload']['name'];

Comments

0

Make sure you use the name of the input field in :

which is imageUpload

change this : $nama_file = $_FILES['images']['name']; to this

$nama_file = $_FILES['imageUpload']['name'];

also :

move_uploaded_file($_FILES['image']['tmp_name'], "images/".$_FILES['image']['name']);

to :

move_uploaded_file($_FILES['imageUpload']['tmp_name'], "images/".$_FILES['imageUpload']['name']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.