PHP MYSQL實(shí)現(xiàn)登陸和模糊查詢兩大功能
本文使用的軟件版本如下:PHP版本 5.5.12;MYSQL版本 5.6.17;Apache 2.4.9 用的wampserver
一、PHPMYSQL實(shí)現(xiàn)登陸
一共含有兩個(gè)文件:login.php和logincheck.php;
表單代碼:
<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="登陸" ahref="logincheck.php" /> <a href="register.php">zhuce:</a> </form>
后臺(tái)處理代碼:
<?php if(isset($_POST["submit"])&& $_POST["submit"] == "登陸") { $user= $_POST["username"]; $psw= $_POST["password"]; if($user== "" || $psw == "") { echo"<script>alert('請(qǐng)輸入用戶名或密碼!'); history.go(-1);</script>"; } else { $link= mysqli_connect('localhost', 'sa', '123456','account');//鏈接數(shù)據(jù)庫(kù) 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); //將數(shù)據(jù)以索引方式儲(chǔ)存在數(shù)組中 echo"welcome "; echo$row[0]; } else { echo"<script>alert('用戶名或密碼不正確!');history.go(-1);</script>"; } } } else { echo"<script>alert('Submit Failed!');history.go(-1);</script>"; } ?>
Account數(shù)據(jù)庫(kù)內(nèi)容:
二、PHPMYSQL實(shí)現(xiàn)模糊查詢
查詢數(shù)據(jù)庫(kù)(只給PHP的代碼):
<?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(); ?>
數(shù)據(jù)庫(kù)表的內(nèi)容如下:
查詢:
結(jié)果:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP批量上傳圖片的具體實(shí)現(xiàn)方法介紹.
這篇文章主要介紹了PHP批量上傳圖片的具體實(shí)現(xiàn)方法。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02PHP6 中可能會(huì)出現(xiàn)的新特性預(yù)覽
PHP核心團(tuán)隊(duì)開發(fā)者Pierre Joye近日在官網(wǎng)上貼出了PHP6中可能會(huì)出現(xiàn)的新特性。之所以說(shuō)是“可能會(huì)出現(xiàn)”,是因?yàn)槟壳癙HP6項(xiàng)目還處于草案階段,這些特性還只是一個(gè)想法,還需要討論,隨時(shí)都有可能變更2014-04-04PHP響應(yīng)post請(qǐng)求上傳文件的方法
這篇文章主要介紹了PHP響應(yīng)post請(qǐng)求上傳文件的方法,涉及php針對(duì)post傳輸數(shù)據(jù)處理的相關(guān)技巧,需要的朋友可以參考下2015-12-12php簡(jiǎn)單實(shí)現(xiàn)快速排序的方法
這篇文章主要介紹了php簡(jiǎn)單實(shí)現(xiàn)快速排序的方法,涉及php針對(duì)數(shù)組與字符串的操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04php 獲取mysql數(shù)據(jù)庫(kù)信息代碼
有時(shí)候我們需要知道m(xù)ysql數(shù)據(jù)庫(kù)中的一些情況,好在php提供了一些內(nèi)置方法與函數(shù),大家了解下了。2009-03-03php采集自中央氣象臺(tái)范圍覆蓋全國(guó)的天氣預(yù)報(bào)代碼實(shí)例
這篇文章主要介紹了php采集自中央氣象臺(tái)范圍覆蓋全國(guó)的天氣預(yù)報(bào)代碼實(shí)例,較為詳細(xì)的分析了采集的技巧及對(duì)應(yīng)接口的調(diào)用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01ThinkPHP3.2.3所有的單字母方法整理總結(jié)
ThinkPHP3.2.3在以前是一款廣受歡迎的PHP開發(fā)框架,現(xiàn)在雖然除了版本5和6,但仍有不少項(xiàng)目使用ThinkPHP3。ThinkPHP3中的字母函數(shù)是以字母開頭的一類函數(shù),其作用是非常豐富的,包括字符串處理、文件處理、日期時(shí)間處理以及HTTP協(xié)議處理等。2023-07-07