本文使用的软件版本如下:php版本 5.5.12;mysql版本 5.6.17;apache 2.4.9 用的wampserver
一、phpmysql实现登陆
一共含有两个文件:login.php和logincheck.php;
表单代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<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><br> |
后台处理代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php if (isset( $_post [ "submit" ])&& $_post [ "submit" ] == "登陆" ) { $user = $_post [ "username" ]; $psw = $_post [ "password" ]; if ( $user == "" || $psw == "" ) { echo "<script>alert('请输入用户名或密码!'); history.go(-1);</script>" ; } 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 "<script>alert('用户名或密码不正确!');history.go(-1);</script>" ; } } } else { echo "<script>alert('submit failed!');history.go(-1);</script>" ; } ?> |
account数据库内容:
二、phpmysql实现模糊查询
查询数据库(只给php的代码):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?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(); ?> |
数据库表的内容如下:
查询:
结果:
以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。