undefined array key in json pdo php

Viewed 25

When I try to insert into the database and I got that problem, what should I do?

    <div class="form-group"> 
        <label for="image" class="form-label">Image</label> 
        <input type="file" name="txtPhoto" id="txtPhoto" class="form-control"> 
    </div>
if ($_GET['data'] == 'add_student') {

    $picture = $_FILES['txtPhoto']['name'];
    move_uploaded_file($_FILES['txtPhoto']['tmp_name'], "Images/$picture");

    $sql = "INSERT INTO tbl_student (photo)
             values (:photo);";

    $insert = $conn->prepare($sql);
    $insert->bindParam(':photo', $picture);

    if ($insert->execute()) {
        echo json_encode("Insert Success");
    } else {
        echo json_encode("Insert Faild");
    }

I got this error

Warning: Undefined array key "txtPhoto" in D:\Year3\PHP Programming\Testing_PHP\libSystem\admin\student_json.php on line 54

Warning: Trying to access array offset on value of type null in D:\Year3\PHP Programming\Testing_PHP\libSystem\admin\student_json.php on line 54

0 Answers
Related