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