当我尝试从登录页面(index.php)加载上面的 php 页面时,没有错误,但是当我登录后尝试从应用程序中的任何其他页面加载它时,它在控制台上给我一个未捕获的语法错误。它指向脚本并表示 php 变量 $name 未定义。
<?php
if (isset($_POST["login"])) {
session_start();
$_SESSION["email"] = $_POST["email"];
$email = $_POST["email"];
$password = $_POST["password"];
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'attendance_system';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Failed to connect: " . $conn->connect_error);
} else {
$success = false;
$query = "SELECT * FROM student";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
if ($row["email"] === $email && $row["password"] === $password) {
$name = $row["name"];
$age = $row["age"];
$criteria = $row["attendance_criteria"];
$course = $row["course"];
$college = $row["college_name"];
$attendance = $row["attendance"];
$success = true;
break;
}
}
if ($success === false) {
header("Location: index.php");
}
}
}
if (isset($_POST["signup"])) {
session_start();
$_SESSION["email"] = $_POST["email1"];
$email = $_POST["email1"];
$password = $_POST["password1"];
$name = $_POST["name"];
$age = $_POST["age"];
$criteria = 100;
$course = null;
$college = null;
$attendance = 0;
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'attendance_system';
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
die("Failed to connect: " . $conn->connect_error);
} else {
$query = "INSERT INTO student SET email = '$email', name = '$name', age = '$age', password =
'$password' ";
$result = $conn->query($query);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Attendance Manager - Home</title>
<link rel="stylesheet" href="../css/skeleton.css">
<link rel="stylesheet" href="../css/home.css">
<link rel="icon" type="image/jpg" href="../media/icon.png">
</head>
潇湘沐
相关分类