首页 > 解决方案 > 无法使用 phpMyAdmin 获取数据

问题描述

我正面临有关 Bootstrap 模态的问题。

当我使用一个简单的表单时,我的数据就会被获取,我也可以编辑和更新它。但是当我使用 Bootstrap 模态实现它时,它会向我显示如下错误:

“注意:尝试访问第 84 行 C:\xampp\htdocs\KFUEIT_RYK\Student_Data.php 中 null 类型值的数组偏移量”

由于以下原因发生错误:

<label>Student Roll No</label> 
<input type="text" value="<?php echo $data_select['s_Roll_No'];?>" name="Student_RollNo" class="form-control" required> 
<label>Student Name</label> –

我的代码:

<?php
$selected_record = $_GET['s_id'];
$query_select = mysqli_query($con, "SELECT * FROM `student_table` where s_id ='$selected_record'  ");
$data_select = mysqli_fetch_array($query_select);
?> 
<!-- Update Code -->
<?php
if (isset($_POST['Update_Record'])) 
{
    $student_rollno = $_POST['Student_RollNo'];
    $student_name=$_POST['Student_Name'];
    $student_father=$_POST['Student_Father'];
    $student_class=$_POST['Student_Class'];
    $student_email=$_POST['Student_Email'];
    $query_update = mysqli_query($con, "UPDATE `student_table` set 
        s_Roll_No = '$student_rollno',
        s_Name = '$student_name',
        s_Father = '$student_father',
        s_Class='$student_class',
        s_Email='$student_email'
        where s_id = '$selected_record'");
    header("location: Student_Data.php");
}
?>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria- labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="" method="POST">
                    <label>Student Roll No</label>
                    <input type="text" value="<?php echo $data_select['s_Roll_No'];?>" name="Student_RollNo" class="form-control" required>
                    <label>Student Name</label>
                    <input type="text" value="<?php echo $data_select['s_Name']; ?>" name="Student_Name" class="form-control" required>
                    <label>Student Father Name</label>
                    <input type="text" value="<?php echo $data_select['s_Father']; ?>" name="Student_Father" class="form-control" required>
                    <label>Student Class</label>
                    <input type="text" value="<?php echo $data_select['s_Class']; ?>" name="Student_Class" class="form-control" required>
                    <label>Student Email</label>
                    <input type="text" value="<?php echo $data_select['s_Email']; ?>" name="Student_Email" class="form-control" required>
                    <button type="submit" name="Update_Record" class="btn btn-primary">Update</button>
                </form>
            </div>
        </div>
    </div>
</div>

标签: phpmysql

解决方案


我怀疑这可能是由于访问了输入字段的 $data_select 数组(例如 $data_select['s_Roll_No'])。

如果 mysql 查询为 $data_select 返回空值(这很可能是 $_GET['s_id'] 未设置或数据库中没有此类记录的情况),那么您将访问空变量的数组偏移量。

您应该先检查数组是否为空,然后再访问它。


推荐阅读