Home  >  Article  >  Backend Development  >  PHP MYSQL implements two major functions: login and fuzzy query, mysql fuzzy query_PHP tutorial

PHP MYSQL implements two major functions: login and fuzzy query, mysql fuzzy query_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:59:13769browse

PHP MYSQL implements two major functions: login and fuzzy query. MySQL fuzzy query

The software versions used in this article are as follows: PHP version 5.5.12; MYSQL version 5.6.17; Apache 2.4 .9 used wampserver
1. Login with PHPMYSQL
Contains a total of two files: login.php and logincheck.php;
Form code:

<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" />

      

  <a href="register.php">zhuce:</a>
</form><br />

Background processing code:

<&#63;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>";

     }

 

&#63;>

Account database content:

2. PHPMYSQL implements fuzzy query

Query database (only code for PHP):

<&#63;php

     $mysqli=newmysqli();             

     $mysqli->connect("localhost","sa", "123456");

     if(mysqli_connect_errno()) {

          printf("Failllllll:%s\n", 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;    

&#63;> Totel

<&#63;php echo $totalRows_rsbooks &#63;>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>

 <&#63;php do { &#63;>

  <tr>

   <td><&#63;php echo $row_rsbooks['Name']; &#63;></td>

   <td><&#63;php echo $row_rsbooks['ISBN']; &#63;></td>

   <td><&#63;php echo $row_rsbooks['Store']; &#63;></td>

   <td><fontcolor="#110BAA">rent</font></td>

  </tr>

  <&#63;php } while ($row_rsbooks = $rsbooks->fetch_assoc()); &#63;>

</table>

<&#63;php

 $rsbooks->close(); 

 $mysqli->close();

&#63;>

The contents of the database table are as follows:

Query:

Result:

The above is the entire content of this article. I hope it will be helpful to everyone in learning PHP programming.

Articles you may be interested in:

  • Two steps to teach you how to open a MySQL database remote login account
  • How to implement MySQL single table multi-keyword fuzzy query
  • PHP MYSQL membership system login and permission judgment implementation code
  • A simple web password login php code
  • Mysql added new user cannot log in solution
  • Detailed introduction to the use of wildcards in MySql like fuzzy query
  • PHP jumps to the pre-login page after login to implement ideas and codes
  • Session exit login problem in php
  • Fuzzy query in mysql Introduction to four usages
  • Thinkphp implements like fuzzy query examples

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1099081.htmlTechArticlePHP MYSQL implements two major functions: login and fuzzy query. MySQL fuzzy query The software version used in this article is as follows: PHP version 5.5 .12; MYSQL version 5.6.17; wampserver used by Apache 2.4.9 1....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn