Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从MYSQL数据库检索用户名_Php_Mysql_Sidebar_Rank - Fatal编程技术网

Php 从MYSQL数据库检索用户名

Php 从MYSQL数据库检索用户名,php,mysql,sidebar,rank,Php,Mysql,Sidebar,Rank,答复问题: 所以我在我的网站上做了一个登录和注册的功能,但现在我想 希望将用户名和排名添加到侧边栏。。但我不能 弄清楚怎么做,这就是为什么我要请你帮忙。 Signup.inc.php: <?php session_start(); include '../dbh.php'; $fname = $_POST['fname']; $lname = $_POST['lname']; $uid = $_POST['uid']; $pwd = $_POST['pwd']; if (empty(

答复问题:

所以我在我的网站上做了一个登录和注册的功能,但现在我想 希望将用户名和排名添加到侧边栏。。但我不能 弄清楚怎么做,这就是为什么我要请你帮忙。 Signup.inc.php:

<?php
session_start();

include '../dbh.php';

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

if (empty($fname)) {
    header("Location: ../parts/signup.php?error=empty");
    exit();
}
if (empty($lname)) {
    header("Location: ../parts/signup.php?error=empty");
    exit();
}
if (empty($uid)) {
    header("Location: ../parts/signup.php?error=empty");
    exit();
}
if (empty($pwd)) {
    header("Location: ../parts/signup.php?error=empty");
    exit();
} else {
$sql = "SELECT uid FROM users WHERE uid='$uid'";
$result = mysqli_query($conn, $sql);
$uidcheck = mysqli_num_rows($result);
if ($uidcheck > 0) {
    header("Location: ../parts/signup.php?error=username");
    exit();
} else {
    $enpwd = password_hash($pwd, PASSWORD_DEFAULT);
    $sql = "UPDATE users (fname, lname, uid, pwd) 
    VALUES ('$fname', '$lname', '$uid', '$enpwd')";

    $result = mysqli_query($conn, $sql);
    header("Location: ../index.php");}
}

---------侧栏:

    <?php
    session_start();
    if(!isset($_SESSION['id'])){ //if login in session is not set
        header("Location: ../index.php");
    }
    include '../include/idtouser.sinc.php';
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>LoginSystem</title>
        <link rel="stylesheet" href="../css/global.css" type="text/css">
    </head>
    <body>
    <header id="closeNav">
        <nav>
              <div onclick="toggleNav()" id="star"><span class="hamburgerico">☰</span></div>
              <div class="profilePicture"></div>
              <div id="username">Username</div>
              <div id="rank"><p>Rank</p></div>

            <ul>
              <li><a href="#">Dashboard</a></li>
              <li><a href="#">Projects</a></li>
              <li><a href="#">Placeholder</a></li>
              <li><a href="#">Placeholder</a></li>
              <li><a href="#">Placeholder</a></li>
              <li><a href="../include/logout.inc.php">Log Out</a></li>
            </ul>
        </nav>
</header>

登录系统
☰
用户名
等级


我这样做的正确方法是什么

未回答的问题:
还有——在侧边栏中发布之前,有没有办法将我的排名(1,2,3,4,5)转换为实际的排名名称?

在登录页面中,添加以下内容:

$_SESSION['uid']        =   $row[1];
假设第[1]行包含用户id或用户名

然后在侧栏中:

<?php echo $_SESSION['uid']; ?>


我不知道排名是为了什么,但你可以用与用户名类似的方式呼应排名

2016年自制的注册脚本听起来不正确。你的脚本易受sql攻击injections@MasivuyeCokile我知道,我还没有解决这个问题,不过我知道:DHey,不知道为什么,但这对我不起作用(?)我编辑了$row[1]到2,因为这是我的UID,但它仍然不起作用(?)我可以再问一个问题吗,如果排名是“1->5”,在将其发布到侧边栏之前,我如何将其转换为实际排名DHello,@fizzi我只是想知道你是否也能回答上面的问题:如果你使用phpmyadmin,那么添加另一个名为rank的字段,其值为1,2,3,4,5,作为类型enum。假设它存储为第[4]行。然后以同样的方式在登录页面$_SESSION['rank']=$row[4];然后在侧栏中:
<?php echo $_SESSION['uid']; ?>