Php 如何解决这个未定义的索引:?

Php 如何解决这个未定义的索引:?,php,bootstrap-4,Php,Bootstrap 4,如何解决此错误?我必须尝试任何东西,但结果都是一样的错误。请帮我解决这个问题 这是我在update.php中的代码: 您需要使用isset来避免这些错误。下面给出了类似的例子 <?php include_once 'config.php'; if (isset($_POST['employee_id'])) { $employee_id=$_POST['employee_id']; $name=$_POST['name']; $date_of_birth=$_POST['date_of_

如何解决此错误?我必须尝试任何东西,但结果都是一样的错误。请帮我解决这个问题

这是我在update.php中的代码:

您需要使用isset来避免这些错误。下面给出了类似的例子

<?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";
}
?>
注意:使用准备好的查询以避免sql注入攻击


将从第4行到文件末尾的所有代码放在下面的if语句中

if (!empty($_GET['employee_id'])) {

    // your code 
}
此外,您的代码对于SQL注入、XSS、CSRF攻击也不安全。您可以使用库来保护代码免受CSRF攻击


使用PDO保护SQL注入。

每个字段设置空值employee_id='';var\u dump$\u POST提供了什么?您可以接受SQL注入。参数化查询。这个问题可能会被否决,因为发布代码图像的链接被认为是破坏性的格式设置,使代码很难复制。另外,请不要重复您所说的。对不起,我仍在学习用代码更新您的问题,而不是图像,然后我将正确地帮助您。您需要将update.php代码粘贴到给定的方法中。我制作了它。请帮我在给定的链接上键入我抱歉..这是犯同样的错误。如果设置为$\u GET['employee\u id']{//将php代码粘贴到此处}
<?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";
}
?>
if (!empty($_GET['employee_id'])) {

    // your code 
}