Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

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,这样可以吗?该怎么写?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

登录完成后,把用户id,用户昵称,手机号,邮箱等个人信息存放到 session 里呗.后续显示的地方直接从 session 里读啊.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...