我收到这个错误:
注意:尝试访问 null 类型值的数组偏移量
当我想更新的时候。我把代码放在下面,请帮助我如何解决这个问题以及故障和问题在哪里?(正常情况下没有错误,但是当我使用ctrl+U并查看源代码时,所有字段都显示该错误。)我在网站上搜索了很多,但没有找到正确的答案或结果。
在editform.php中
<?php
include_once "InsertDataDatabases.php";
$id = (isset($_POST['id']) ? $_POST['id'] : '');
$query = InsertDataDatabases::SelectDateId($id);
$item = [];
$item = mysqli_fetch_assoc($query);
?>
<form action="updatedata.php" method="post" enctype="multipart/form-data">
<?php CSRF::CreateToken(); ?>
<input type="text" name="id" value="<?php echo $item['id']; ?>"><br>
<label for="name">Name:</label>
<input type="text" name="name" value="<?php echo $item['name']; ?>"><br><br>
<label for="email">Email:</label>
<input type="email" name="email" value="<?php echo $item['email']; ?>"><br><br>
<input type="file" name="image" value="images/slider/<?php echo $item['image']; ?>"><br>
<img src="images/slider/<?php echo $item['image']; ?> " width="50px" height="50px" alt=''><br>
<input type="submit" name="updatebtn" value="UPDATE">
</form>
在 updatedata.php 中
<?php
include_once "InsertDataDatabases.php";
include_once "DataBase.php";
include_once "CSRF.php";
$con = DataBase::ConnectOpen();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['updatebtn'])) {
if (CSRF::ValidateToken($_POST["token"])) {
$id = htmlentities(mysqli_real_escape_string($con, $_POST['id']));
$name = htmlentities(mysqli_real_escape_string($con, $_POST['name']));
$email = htmlspecialchars(mysqli_real_escape_string($con, filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL)));
$image = $_FILES['image'];
InsertDataDatabases::UpdateData($id, $name, $email, $image);
mysqli_close($con);
header("Location: index.php");
}
}
}
并在 InsertDataDatabases.php 中
public static function SelectDateId($id)
{
self::ConnectDataBase();
return mysqli_query(self::$con, "SELECT * FROM user WHERE id = '{$id}'");
}
侃侃尔雅