[Solved] How can i solve this Undefined index:?


You need to use isset() to avoid these errors. something like given below.

<?php
include_once 'config.php';
if (isset($_POST['employee_id'])) {

$employee_id=$_POST['employee_id'];
$name=$_POST['name'];
$date_of_birth=$_POST['date_of_birth'];
$gender=$_POST['gender'];
$marital_status=$_POST['marital_status'];
$nationality=$_POST['nationality'];
$present_address=$_POST['present_address'];
$city=$_POST['city'];
$country=$_POST['country'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$nip=$_POST['nip'];
$status=$_POST['status'];
$designation=$_POST['designation'];
$joining_date=$_POST['joining_date'];
$leaving_date=$_POST['leaving_date'];
$picture = basename($_FILES['picture']['name']);

if (!empty($_FILES['picture'])) {   
    $path = "admin/gambar/";
    $path = $path . basename($_FILES['picture']['name']);
    if (move_uploaded_file($_FILES['picture']['tmp_name'], $path)) {
        echo "The file " . basename($_FILES['picture']['name']) .
        " has been uploaded";
    } else {
        echo "There was an error uploading the file, please try again";
    }
}

$query = "UPDATE employee_list set name="$name", date_of_birth="$date_of_birth", gender="$gender", marital_status="$marital_status", nationality='$nationality', present_address="$present_address", city='$city', country='$country', phone="$phone", email="$email", nip=$nip, status="$status", designation='$designation', joining_date="$joining_date", leaving_date="$leaving_date", picture="$picture" where employee_id=$employee_id";
}
?>

Note:Use prepared query to avoid sql injection attack.

8

solved How can i solve this Undefined index:?