php登录代码

 

供大家参考

<?php

         error_reporting(0);

         header("content_type:text/html;charset=gbk");

         $conn=mysql_connect("localhost","root","") or die("链接错误");

         mysql_select_db("phptest",$conn);

//     echo "链接成功"."<br>";

         $username=$_POST['username'];

         $password=$_POST['password'];

//     echo "用户输入的是:"."$username"."<br>"."$password";

         $sqla="select * from user";

         $sqlb="select * from user where username='$username'";

         $sqlc="select * from user where username='$username' and password='$password'";

         $resulta=mysql_query($sqla,$conn);

         $resultb=mysql_query($sqlb,$conn);

         $resultc=mysql_query($sqlc,$conn);

         $numa=mysql_num_rows($resulta);

         $numb=mysql_num_rows($resultb);

         $numac=mysql_num_rows($resultc);

         if($username=="" or $password==""){

                   echo "用户名或密码不能为空";

         }else if($numb>0 ){

                   while($all=mysql_num_rows($result)){

                            echo "$all[username]"."   "."$all[password]"."<br>";

                   }

                   

         }

         

?>

<html>

         <body>

                   <form action="newTest.php" method="post">

                            <ul>

                            <li>username:<input type="text" name="username"/></li>

                            <li>password:<input type="text" name="password"/></li>

                            <li><input type="submit" name="sub"value="sub"/></li>

                   </ul>

                   </form>

         </body>

</html>

 

 

php

相关推荐