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> <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.