Php mysql implements login and fuzzy query functions. mysql fuzzy query
The software version used in this article is as follows: PHP version 5.5.12; MYSQL version 5.6.17; wampserver for Apache 2.4.9
I. PHPMYSQL Login
There are two files in total:Login. phpAndLogincheck. 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 = "login" 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 ('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 indexes 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:
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;<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();?>
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.
Articles you may be interested in:
- Two steps to enable the remote login account of the MySQL database
- How to Implement Multi-Keyword fuzzy query in a single MySQL table
- PHP + MYSQL implementation code for permission judgment upon login of the Member System
- A simple web page password to log on to php code
- New mysql users cannot log on.
- MySql like fuzzy query wildcard usage
- PHP jump to the pre-login page after login Implementation ideas and code
- Php session logout and login Problems
- Introduction to four usage of fuzzy query in mysql
- Thinkphp implements like fuzzy search instances