【发布时间】:2021-01-01 02:22:18
【问题描述】:
这是我尝试使用 $_SESSION id 变量从本地服务器获取数据时的代码。在此页面中,我收到错误消息:
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPaasword = "";
$dbName = "ridobiko";
$con = mysqli_connect($dbServername, $dbUsername, $dbPaasword, $dbName) or die(mysqli_error($con));
if(!isset($_SESSION))
{
session_start();
}
$bike_id = $_SESSION['id'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<table>
<thead>
<tr><b>Bike Brand</b></tr>
<tr><b>Bike Name</b></tr>
<tr><b>Bike Image</b></tr>
<tr><b>Bike rent price</b></tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM bike_details WHERE bike_id = '$bike_id';";
$run_query = mysqli_query($con,$query) or die(mysqli_error($con));
$row = mysqli_fetch_array($run_query);
echo "
<td>".$row['bike_brand']."</td>
<td>".$row['bike_name']."</td>
<td><img src='".$row['bike_image']."' height='100' width='100'></td>
<td>".$row['bike_price']."</td>
";
?>
</tbody>
</table>
</body>
虽然我在上一页设置了 $_SESSION 变量。在此页面中,我与本地服务器连接,并通过此页面将我的详细信息存储在本地服务器中并存储 $_SESSION 变量值:
if($total_accounts>0){
echo "
<script type='text/javascript'>
alert('Bike details alreay exists');
window.location='question1.php';
</script>
";
}
else {
$filename = $_FILES["bike_image"]["name"];
$tempname = $_FILES["bike_image"]["tmp_name"];
$foldername = "bike_image/".$filename;
move_uploaded_file($tempname, $foldername);
$query = "INSERT INTO bike_details (bike_brand,bike_name,bike_price,bike_image) VALUES ('$bike_brand', '$bike_name', '$bike_price', '$foldername');";
$run_query = mysqli_query($con, $query) or die(mysqli_error($con));
$_SESSION['id'] = $bike_id;
echo $_SESSION['id'];
echo "
<script type='text/javascript'>
alert('Bike details updated successfully');
window.location='question2.php';
</script>
";
}
这是我在运行代码时遇到的错误:
Bike BrandBike NameBike ImageBike rent price
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\ridobiko_question1\question2.php on line 56
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\ridobiko_question1\question2.php on line 57
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\ridobiko_question1\question2.php on line 58
Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\ridobiko_question1\question2.php on line 59
【问题讨论】:
-
请不要将代码发布为图片
-
@executable 你能再检查一次吗,我编辑了我的问题。希望对您有所帮助。