PHPMYSQL implements login and fuzzy query functions

Source: Internet
Author: User
Tags learn php programming
This article mainly introduces PHPMYSQL's login and fuzzy query functions, and introduces PHPMYSQL's login and fuzzy query functions, if you are interested, refer to the software versions used in this article: PHP 5.5.12, MYSQL 5.6.17, and wampserver for Apache 2.4.9.
I. PHPMYSQL login
There are two files in total: Login. phpAnd Logincheck. php;
Form code:


Background processing code:

<? Php if (isset ($ _ POST ["submit"]) & $ _ POST ["submit"] = "login ") {$ user = $ _ POST ["username"]; $ psw = $ _ POST ["password"]; if ($ user = "" | $ psw = "") {echo "script alert ('Enter your username or password! '); History. go (-1); script ";} else {$ link = mysqli_connect ('localhost', 'sa ', '123', 'account '); // link to the 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); // store data in the array as an index echo" Welcome "; echo $ row [0];} else {echo" script alert ('The user name or password is incorrect! '); History. go (-1); script ";}}} else {echo" script alert ('submit Failed! '); History. go (-1); script ";}?>

Account database content:

II. implement fuzzy query in PHPMYSQL

Query the database (only for PHP code ):

<?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;
 
  <?php do { ?> 
    <?php } while ($row_rsbooks = $rsbooks->fetch_assoc()); ?> 
  
Name ISBN Store Do
<?php echo $row_rsbooks['Name']; ?> <?php echo $row_rsbooks['ISBN']; ?> <?php echo $row_rsbooks['Store']; ?> rent
<?php $rsbooks->close(); $mysqli->close();?>

The database table content is as follows:

Query:

Result:

The above is all the content of this article. I hope it will help you learn php programming.

Related Article

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.