时间:2021-07-01 10:21:17 帮助过:26人阅读
后台处理代码:
<?php if(isset($_POST["submit"])&& $_POST["submit"] == "登陆") { $user= $_POST["username"]; $psw= $_POST["password"]; if($user== "" || $psw == "") { echo""; } else { $link= mysqli_connect('localhost', 'sa', '123456','account');//链接数据库 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); //将数据以索引方式储存在数组中 echo"welcome "; echo$row[0]; } else { echo""; } } } else { echo""; } ?>
Account数据库内容:
二、PHPMYSQL实现模糊查询
查询数据库(只给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;
Name | ISBN | Store | Do |
<?php echo $row_rsbooks['Name']; ?> | <?php echo $row_rsbooks['ISBN']; ?> | <?php echo $row_rsbooks['Store']; ?> |
数据库表的内容如下:
查询:
结果:
以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。