0

I am trying to upload a file to a folder, this is my error and code.

[01-Feb-2018 22:07:26 America/New_York] PHP Notice:  Undefined index: myimage in /home/grampmkn/public_html/admin/addpost.php on line 27

[01-Feb-2018 22:07:26 America/New_York] PHP Notice: Undefined index: myimage in /home/grampmkn/public_html/admin/addpost.php on line 28

<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
    echo "test6";
    if(isset($_POST['itemname']) and isset($_POST['price']) and isset($_POST['myimage'])){
        echo "test5";
        if(isset($_POST["submit"])) {
            $itemname = $_POST['itemname'];
            $price = $_POST['price'];

            $location="tracylynn/";
            $name=$_FILES['myimage']['name'];
            $temp_name=$_FILES['myimage']['tmp_name'];
            echo "test3";
            if(isset($name)){
                echo "test";
                move_uploaded_file($temp_name, $location.$name);
            }
        }
    }
}
?>



<form class="form-horizontal"
    style="padding-right: 50px; padding-left: 50px; padding-top: 20px;"
    action="" method="post">
    <div class="form-group">
        <label class="control-label col-sm-2">Name:</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" name="itemname" id="itemname"
                placeholder="Item name..">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Price:</label>
        <div class="col-sm-10">
            <input type="number" class="form-control" name="price" id="price"
                placeholder="Price..">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-2">Image:</label>
        <div class="col-sm-10">
            <input type="file" name="myimage" id="myimage">
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" name="submit" id="submit" class="btn btn-default">Submit</button>
        </div>
    </div>
</form>

I've tried searching everywhere for the solution and everything I try does not seam to work.

0 Answers0