php - 如何将一行连接到数据库中的表?
问题描述
我目前正在为我们学校开发一个系统,并且我有一个注册/登录/出勤系统。
问题是我想让一个在我的表行中的用户连接到另一个表。只有他可以访问该表,因为似乎每当我们登录另一个用户时,它都会重定向到同一个网页。
有没有办法解决这个问题?
<?php
$mymail = $_POST["mymail"];
$mypass = $_POST["mypass"];
echo "$mymail";
//database connection to check inside table and query email and password
$servername = "localhost";
$username = "root";
$password = "admin";
$dbname = "sistema";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM userlogin where mymail ='" . $mymail . "' and mypass = '" . $mypass . "'";
$result = $conn->query($sql);
// echo $sql;
if ($result->num_rows > 0) {
// output data of each row
// while($row = $result->fetch_assoc()) {
// echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["idnumber"]. "<br>";
// }
header("Location: http://localhost/sistema/attendance/index.php"); /* Redirect browser */
} else {
header("Location: http://localhost/sistema/signup/index2.html"); /* Redirect browser */
// echo "0 results";
}
$conn->close();
?>
//这只是与数据库的连接以及查询,我将 HTML 表单分开
解决方案
您可以将他的用户 ID 存储在会话中
<?php
// Start the session
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
//after login that user
$_SESSION["id"] = $_Post['id'];
$_SESSION["id"] = $_Post['username'];
?>
您必须在每个页面上都开始会话,并且无论如何您都可以在您的网站上使用该用户 ID 来调用$_SESSION["id"]
如果他点击注销
unset($_SESSION["id"]); & unset($_SESSION["id"]);
推荐阅读
- shared-element-transition - 仅在 Android 10 上的 onPause 后 setEnterSharedElementCallback 不起作用
- android - 如何在 ListView android 中显示原生广告?
- ruby-on-rails - CanCanCan可以加载_和_授权_资源
- python - 带有 Radiobutton 的 Python tkinter 动态输入框
- python - 从文本字段小部件中获取所有值并将它们返回到按钮小部件
- apache-spark - SPARK java.lang.OutOfMemoryError:没有足够的内存来构建表并将表广播到所有工作节点
- nativescript - Radlist 查看可折叠项目动画
- android - AnySoftKeyboard:将语言包集成到 apk 中,无需使用插件
- perforce - 在命令行中创建时如何保存更改列表编号?
- python - / (Divison) 运算符在 numpy 数组中做了什么?