SL_Shuai 2020-08-14 18:27 采纳率: 48.1%
浏览 129

from连接php,php查询数据库进行校验,已经正确登录,但是不懂该怎么样获取用户名?

HTML代码:

<form action="./php/login.php" name="loginform" accept-charset="utf-8" id="login_form" class="loginForm" method="post">
                            <input type="hidden" name="did" value="0"/>
                            <input type="hidden" name="to" value="log"/>
                            <div class="uinArea" id="uinArea">
                                <label class="input-tips" for="u">手机号:</label>
                                <div class="inputOuter" id="uArea">
                                    <input type="text" name="phone" class="inputstyle"/>
                                </div>
                            </div>
                            <div class="pwdArea" id="pwdArea">
                                <label class="input-tips" for="password">密码:</label>
                                <div class="inputOuter" id="pArea">
                                    <input type="password" name="password" class="inputstyle"/>
                                </div>
                            </div>
                            <div style="padding-left:75px;margin-top:20px;">
                                <input type="submit" value="登 录" style="width:150px;" class="button_blue"/>
                            </div>
                        </form>

PHP代码:

<?PHP
    header("Content-Type: text/html; charset=utf-8");
    include('conn.php');//链接数据库
    $phone = $_POST['phone'];//post获得用户名表单值
    $password = $_POST['password'];//post获得用户密码单值
    if ($phone && $password){//如果用户名和密码都不为空
             $sql = "select * from user where phone = '$phone' and password = '$password' ";//检测数据库是否有对应的tel和password的sql
             $res = mysql_query($sql);//执行sql
             $rows = mysql_num_rows($res);//返回一个数值
             if($rows){//0 false 1 true
             header("refresh:0;url=../index.html");//如果成功跳转至index.html页面
             exit;
             }else{
                echo "手机号或密码错误";
                echo "
                <script>
                setTimeout(function(){window.location.href='../login.html';},1000);
                </script>";
                //如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
             }
             }else{//如果手机号或密码有空
                echo "没有获取到手机号或者密码";
                echo "
                <script>
                setTimeout(function(){window.location.href='../login.html';},1000);
                </script>";
                //如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
            }
    mysql_close();//关闭数据库
?>

这是登录的html和php,用手机号码作为账号进行登录,可以正常登录,想在登录后跳转的index.html页面的右上角显示登录用户的昵称,就是对应的user_name,通过phone查询表获取这个user_name,这样可以吗?该怎么写?然后html怎么输出出来?

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-14 20:39
    关注

    $res = mysql_query($sql);
    $row1= $res->fetch_assoc();
    $uid = $row["username"]; //假设你的字段叫做username

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用