PHP MySQL implementation of landing and fuzzy query two major functions _php skills

Source: Internet
Author: User

The software version used in this article is as follows: PHP version 5.5.12;mysql version 5.6.17;apache 2.4.9 wampserver
first, Phpmysql to achieve landing
Altogether contains two documents: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=" Landing "ahref=" logincheck.php "/> <a href="

  register.php ">zhuce:</a>
</ Form>

Background processing code:

<?php if (Isset ($_post["submit")) && $_post["submit"] = = "Login") {$user = $_post["username"

          ];

          $PSW = $_post["password"]; if ($user = = "" | | $PSW = = "") {echo "<script>alert" Please enter your username or password! ');

          History.go ( -1);</script> ";

              else {$link = Mysqli_connect (' localhost ', ' sa ', ' 123456 ', ' account ');//Linked database

              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);

                   Storing data in an array in an indexed way echo "Welcome";

              ECHO$ROW[0]; else {echo ' <script>alert ('User name or password is incorrect!

              '); History.go ( -1);</script> "; }} else {echo ' <script>alert (' Submit failed! ');

     History.go ( -1);</script> ";

 }?>

Account Database content:

Two, Phpmysql realizes the fuzzy inquiry

Query the database (code for PHP only):

<?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;

?> Totel <?php echo $totalRows _rsbooks?>books; <table width= "border=" 1 "> <tr> <td bgcolor=" #99CCFF "align=" center ">Name</td> &LT;TD BG Color= "#99CCFF" align= "center" >ISBN</td> <td bgcolor= "#99CCFF" align= "Center" >Store</td> < TD bgcolor= "#99CCFF" align= "center" >Do</td> </tr> <?php do {?> <tr> <td><?p HP echo $row _rsbooks[' Name '];?></td> <td><?phpecho $row _rsbooks[' ISBN '];?></td> <td><?php echo $row _rsbooks[' Store ';?></td> <td ><fontcolor= "#110BAA" >rent</font></td> </tr> <?php} while ($row _rsbooks = $rsbooks-&G 

 T;FETCH_ASSOC ());?> </table> <?php $rsbooks->close ();

$mysqli->close ();

 ?>

The contents of the database table are as follows:

Inquire:

Results:

The above is the entire content of this article, I hope that you learn PHP programming help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.