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

标签 php mysql sql phpmyadmin

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

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

这是分数.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/

相关文章:

MYSQL 查询 DateTime,查找现有预订

php - Laravel 4 中 Controller 过滤器的运行顺序是什么

php - 为每个 id 添加元值,其中 post_type = ??文字新闻

Mysql根据小时累计求和

mysql - #1005 - 无法创建表 'disertation.#sql-d38_40'(错误号 : 150)

c# - 如何根据组合框中的选定值从数据库中检索数据?

mysql - 如何使用sql查询将第二个单位的数据聚合为一个平均分钟单位

java - 从 api 返回多个 order_id 的值

php - 保持 PHP 和 HTML 分离

php - 将电子邮件地址输入 MYSQL 数据库