【问题标题】:Unable to fetch data using phpMyAdmin无法使用 phpMyAdmin 获取数据
【发布时间】:2020-07-10 04:11:23
【问题描述】:

我遇到了关于 Bootstrap 模态的问题。

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

"注意:试图访问类型为 null 的数组偏移量 C:\xampp\htdocs\KFUEIT_RYK\Student_Data.php 第 84 行"

因此发生错误:

<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>

【问题讨论】:

  • 如果设置了$_POST['Update_Record'],您的代码会重定向到新页面,在这种情况下,$data_select 将不会设置。

标签: php mysql


【解决方案1】:

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

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

你应该在访问它之前首先检查数组是否为空。

【讨论】:

  • 我很难弄清楚那里到底发生了什么。我在数据库中有超过 15 条记录,当我用没有模态的简单表格检查它时,它工作正常,但它给我模态错误。不知道为什么它给我错误
猜你喜欢
  • 2020-04-09
  • 1970-01-01
  • 2021-12-18
  • 2021-05-26
  • 1970-01-01
  • 2018-01-25
  • 2012-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多