• PHP MYSQL登陆和模糊查询


    PHP MYSQL登陆和模糊查询
     
    PHP版本 5.5.12    MYSQL版本 5.6.17  Apache 2.4.9 用的wampserver
    一、PHPMYSQL实现登陆: 
    一共含有两个文件:login.php和logincheck.php;

    表单代码:

    <form action="logincheck.php"method="post">
    
             Yonghu:<inputtype="text" name="username" />
    
       <br />
    
       Mima:<input type="password" name="password" />
    
       <br />
    
       <input type="submit" name="submit" value="登陆" ahref="logincheck.php" />
    
       &nbsp;&nbsp;&nbsp;&nbsp;
    
       <a href="register.php">zhuce:</a>
    
    </form>

    后台处理代码:

    <?php
    
             if(isset($_POST["submit"])&& $_POST["submit"] == "登陆")
    
             {
    
                       $user= $_POST["username"];
    
                       $psw= $_POST["password"];
    
                       if($user== "" || $psw == "")
    
                       {
    
                                echo"<script>alert('请输入用户名或密码!'); history.go(-1);</script>";
    
                       }
    
                       else
    
                       {
    
                                $link= mysqli_connect('localhost', 'sa', '123456','account');//链接数据库
    
                                mysqli_select_db($link,"account");
    
                                mysqli_query($link,'setname utf8');
    
                                $sql= "selectuser from zhanghu where user = '$_POST[username]'";
    
                                $result=mysqli_query($link,$sql)or die("Failed".mysql_error());
    
                                if($num=mysqli_num_rows($result))
    
                                {
    
                                         $row= mysqli_fetch_array($result);       //将数据以索引方式储存在数组中
    
                                         echo"welcome ";
    
                                         echo$row[0];
    
                                }
    
                                else
    
                                {
    
                                         echo"<script>alert('用户名或密码不正确!');history.go(-1);</script>";
    
                                }
    
                       }
    
             }
    
             else
    
             {
    
                       echo"<script>alert('Submit Failed!');history.go(-1);</script>";
    
             }
    
     
    
    ?>
    
     

     

    Account数据库内容:


    二、PHPMYSQL实现模糊查询

    查询数据库(只给PHP的代码):

    <?php
    
             $mysqli=newmysqli();                         
    
             $mysqli->connect("localhost","sa", "123456");
    
             if(mysqli_connect_errno()) {
    
                       printf("Failllllll:%s
    ", mysqli_connect_error());
    
                       exit();
    
             }
    
             $mysqli->select_db("booklib");   
    
             $mysqli->query("SETNAMES utf8");      
    
             $rsbooks= $mysqli->query("select * from books where Name like'%$_POST[bookname]%'");
    
       $row_rsbooks = $rsbooks->fetch_assoc();
    
       $totalRows_rsbooks = $rsbooks->num_rows;       
    
    ?> Totel
    
    <?php echo $totalRows_rsbooks ?>books;
    
    <table width="600"border="1">
    
     <tr>
    
       <td bgcolor="#99CCFF"align="center">Name</td>
    
       <td bgcolor="#99CCFF" align="center">ISBN</td>
    
       <td bgcolor="#99CCFF"align="center">Store</td>
    
       <td bgcolor="#99CCFF"align="center">Do</td>
    
     </tr>
    
     <?php do { ?>
    
       <tr>
    
         <td><?php echo $row_rsbooks['Name']; ?></td>
    
         <td><?php echo $row_rsbooks['ISBN']; ?></td>
    
         <td><?php echo $row_rsbooks['Store']; ?></td>
    
         <td><fontcolor="#110BAA">rent</font></td>
    
       </tr>
    
       <?php } while ($row_rsbooks = $rsbooks->fetch_assoc()); ?>
    
    </table>
    
    <?php
    
     $rsbooks->close(); 
    
     $mysqli->close();
    
    ?>

    数据库表的内容如下:

    查询:

     

    结果:

    如果,您认为阅读这篇博客让您有些收获,不妨拿出手机微信扫一扫

    您的资助是我最大的动力!
    金额随意,欢迎来赏!

  • 相关阅读:
    Linux内核链表——看这一篇文章就够了
    2的幂和按位与&——效率
    fgets注意事项
    GDB TUI
    GDB TUI
    linux shell命令行选项与参数用法详解
    What are the differences between Perl, Python, AWK and sed
    What is the difference between sed and awk
    /proc/sysrq-trigger
    C++ Sqlite3的基本使用
  • 原文地址:https://www.cnblogs.com/w1570631036/p/4951463.html
Copyright © 2020-2023  润新知