我该如何解决这个未定义的索引:? [英] How can i solve this Undefined index:?

查看:209
本文介绍了我该如何解决这个未定义的索引:?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决此错误?我必须尝试任何操作,但结果是相同的错误.请帮助我解决此问题错误

[My error][1]

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

And this is my Code in update.php:

    <?php
include_once 'config.php';

$employee_id=$_GET['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";
?>


Thank you :)

推荐答案

您需要使用isset()以避免这些错误.如下所示.

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";
}
?>

注意:使用准备好的查询来避免SQL注入攻击.

Note:Use prepared query to avoid sql injection attack.

这篇关于我该如何解决这个未定义的索引:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆