小编use*_*307的帖子

在PHP中登录错误消息

我是PHP代码的新手,如果用户输入了错误的用户标识或密码,我想在login.php中显示错误信息.我写了两页代码.login.php页面将用户名和密码提交给check.php页面.如果用户名和密码正确,则重定向到xyz.php else到登录页面.

login.php //登录页面

<form name="login" enctype="multipart/form-data" action="checkpage.php" method="post">
            <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <th>Username</th>
                <td><input type="text" name="username" value="sandeep" onfocus="this.value=''" class="login-inp" /></td>
            </tr>
            <tr>
                <th>Password</th>
                <td><input type="password" name="password" class="login-inp" /></td>
            </tr>
            <tr>
                <th></th>
                <td valign="top"><input type="checkbox" class="checkbox-size" id="login-check" /><label for="login-check">Remember me</label></td>
            </tr>
            <tr>
                <th></th>
                <td><input type="submit" class="submit-login"  /></td>
            </tr>

            <tr><th></th><td>w want to display error message here..</td></tr>

</table></form>
Run Code Online (Sandbox Code Playgroud)

checkpage.php //连接页面

<?php
    session_start();
    //connecting to db
    $username=$_POST['username'];
    $pwd=$_POST['password'];
    $q="select *from xyz where username='$username' AND password='$pwd'";
    $qry=mysql_query($q);
    if(mysql_num_rows($qry)>0)
    {
        $_SESSION['username']=$username;
        echo "<script>window.open('xyz.php','_self')</script>"; 
        } …
Run Code Online (Sandbox Code Playgroud)

php

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×1