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ù)學(xué)運(yùn)算函數(shù)大匯總(經(jīng)典值得收藏)
這篇文章主要介紹了PHP數(shù)學(xué)運(yùn)算函數(shù),匯總分析了常見的PHP數(shù)學(xué)運(yùn)算函數(shù)的功能,使用方法與注意事項(xiàng),需要的朋友可以參考下2016-04-04
KindEditor在php環(huán)境下上傳圖片功能集成的方法示例
這篇文章主要介紹了PHP環(huán)境下如何實(shí)現(xiàn)使用KindEditor編輯器上傳圖片,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
php中關(guān)于codeigniter的xmlrpc的類在進(jìn)行數(shù)據(jù)交換時(shí)的類型問題
在使用codeigniter的xmlrpc類進(jìn)行客戶端/服務(wù)端請(qǐng)求應(yīng)答的時(shí)候,客戶端需要發(fā)送請(qǐng)求參數(shù)給服務(wù)端,服務(wù)端在接受到參數(shù)之后進(jìn)行參數(shù)分析,分拆參數(shù)之后分配給正確的方法進(jìn)行處理,處理之后反饋一個(gè)response給客戶端。2011-07-07
PHP實(shí)現(xiàn)的隨機(jī)IP函數(shù)【國(guó)內(nèi)IP段】
這篇文章主要介紹了PHP實(shí)現(xiàn)的隨機(jī)IP函數(shù),可實(shí)現(xiàn)輸出國(guó)內(nèi)IP段的功能,涉及php字符串與數(shù)組的計(jì)算操作相關(guān)技巧,需要的朋友可以參考下2016-07-07
盤點(diǎn)PHP和ASP.NET的10大對(duì)比!
本文主要針對(duì)開源 PHP 和非開源的 ASP.NET 在性能、成本、可擴(kuò)展性,技術(shù)支持和復(fù)雜性等方面進(jìn)行比較,感興趣的小伙伴們可以參考一下2015-12-12

