【发布时间】: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">×</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将不会设置。