本文使用的软件版本如下:PHP版本 5.5.12;MysqL版本 5.6.17;Apache 2.4.9 用的wampserver
一、PHPMysqL实现登陆
一共含有两个文件:login.PHP
和logincheck.PHP;
表单代码:PHP;">
PHP
if(isset($_POST["submit"])&& $_POST["submit"] == "登陆")
{
$user= $_POST["username"];
$psw= $_POST["password"];
if($user== "" || $psw == "")
{
echo"<script>alert('请输入<a href="https://www.jb51.cc/tag/yonghuming/" target="_blank" class="keywords">用户名</a>或密码!'); history.go(-1);</script>";
}
else
{
$link= <a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_connect('localhost','sa','123456','account');//<a href="https://www.jb51.cc/tag/lianjie/" target="_blank" class="keywords">链接</a><a href="https://www.jb51.cc/tag/shujuku/" target="_blank" class="keywords">数据库</a>
<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_select_db($link,"account");
<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_query($link,'setname utf8');
$<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>= "selectuser from zhanghu where user = '$_POST[username]'";
$result=<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_query($link,$<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>)or die("<a href="https://www.jb51.cc/tag/Failed/" target="_blank" class="keywords">Failed</a>".<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>_error());
if($num=<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_num_rows($result))
{
$row= <a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_fetch_array($result); //将数据以索引方式储存在数组中
echo"welcome ";
echo$row[0];
}
else
{
echo"<script>alert('<a href="https://www.jb51.cc/tag/yonghuming/" target="_blank" class="keywords">用户名</a>或密码不正确!');history.go(-1);</script>";
}
}
}
else
{
echo"<script>alert('Submit <a href="https://www.jb51.cc/tag/Failed/" target="_blank" class="keywords">Failed</a>!');history.go(-1);</script>";
}
?>
二、PHPMysqL实现模糊查询
PHP;">
$mysqli=newmysqli();
$mysqli->connect("localhost","sa","123456");
if(<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_connect_errno()) {
printf("Failllllll:%s\n",<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i_connect_error());
exit();
}
$<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i->select_db("booklib");
$<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i->query("SETNAMES utf8");
$rsbooks= $<a href="https://www.jb51.cc/tag/MysqL/" target="_blank" class="keywords">MysqL</a>i->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</td>
</tr>
<?php } while ($row_rsbooks = $rsbooks->fetch_assoc()); ?>
</table>
<?php
$rsbooks->close();
$MysqLi->close();
?>
查询:
结果:
原文链接:https://www.f2er.com/php/20394.html