gpt4 book ai didi

php - 使用 PHP 和 MySQL 仅显示当前用户的详细信息

转载 作者:行者123 更新时间:2023-11-29 17:34:23 25 4
gpt4 key购买 nike

在这部分代码中,分数表和个人资料页面都显示了我想要的所有内容,但是它显示了每个人的详细信息,例如

名字姓电子邮件类别用户名但是,我希望用户登录时只能看到自己的详细信息

这是分数.php

    <?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
require("db_connect.php");
session_start();
?>

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">

<?php
$con=mysqli_connect("localhost","username","Password","Database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


$result = mysqli_query($con,"SELECT * FROM Score where 'Username' LIKE _['Username']");


echo "<table border='1'>
<tr>
<th>ID</th>
<th>Username</th>
<th>Score</th>
<th>Gamedate</th>
<th>QuizTitle</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Username'] . "</td>";
echo "<td>" . $row['Score'] . "</td>";
echo "<td>" . $row['Gamedate'] . "</td>";
echo "<td>" . $row['QuizTitle'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

这是 profile.php

<?php
include_once 'db_connect.php';
?>


<!DOCTYPE HTML>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">

<title>Profile page </title>

<?php
$con=mysqli_connect("localhost","Username","password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT `FirstName`,`Surname`,`Email`,`Username`,`Date_Creation`FROM Users ");



while($row = mysqli_fetch_array($result))
{



echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
echo "<b>First name:</b> ". $row['FirstName'];
echo "<br /><b>Last name:</b> ".$row['Surname'];
echo "<br /><b>Email:</b> ".$row['Email'];
echo "<br /><b>Year:</b> ".$row['Username'];
echo "<br /><b>Date created :</b> ".$row['Date_Creation'];
}


mysqli_close($con);
?>
</main>



</html>

这些是我尝试运行该页面时收到的错误。在我更改选择查询之前,它选择了当前登录的用户,但它显示了每个人的信息

This is for the score This is for the profile

最佳答案

SQL 中的单引号用于引用特定字符串,如 'Bob'。如果您尝试检查列的值,请勿将列名称放在引号中,如 'Username'。相反,请将列名称不带引号: where Username like

关于php - 使用 PHP 和 MySQL 仅显示当前用户的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50416027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com