本文給大家分享的是使用PHP+MYSQL實現用戶的增刪改查功能的全部頁面代碼,非常的詳細,也很實用,適合php的初學者,有需要的小伙伴參考下。
文件列表。。文件內容。。
dbconn.php
userListt.php
editUser.php
editDo.php
detailUser.php
deleteUser.php
addUser.php
addDo.php
<dbconn.php>
? 1 2 3 4 5 6 <?php // 創建數據庫連接 $con = mysql_connect("localhost",'root','') or die('error:'.mysql_error()); mysql_select_db('hyxx',$con) or die('error:'.mysql_error()); mysql_query('set NAMES utf8'); ?><userListt.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 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>會員信息列表</title> </head> <body> <table border="1" cellspacing="0" cellpadding="0" id="userList" align="center"> <tr align="center"> <td>id</td> <td>用戶名</td> <td>密碼</td> <td>性別</td> <td>年齡</td> <td>出生年月</td> <td>愛好</td> <td>注冊時間</td> <td>最後登錄時間</td> <td>操作</td> </tr> <?php require_once 'inc/dbConn.php'; //這是啥東東。。 date_default_timezone_set("PRC"); //讀數據。。。 $sql = "select * from user order by id asc"; $result = mysql_query($sql,$con); $userList = ''; while($rs = mysql_fetch_array($result)){ $userList[] = $rs; } // 循環用戶列表 foreach ($userList as $user){ echo " <tr> <td> ".$user['id']."</td> <td> ".$user['username']."</td> <td> ".$user['password']."</td> <td> ".$user['sex']."</td> <td> ".$user['age']."</td> <td> ".date("Y-m-d",$user['birthday'])."</td> <td> ".$user['hobby']."</td> <td> ".date("Y-m-d",$user['add_time'])."</td> <td> ".date("Y-m-d",$user['last_login'])."</td> <td> <a href='addUser.php'>增</a> <a href='deleteUser.php?id=".$user['id']."');"> 刪</a> <a href='editUser.php?id=".$user['id']."');"> 改</a> <a href='detailUser.php?id=".$user['id']."');"> 查</a> </td> </tr> "; } ?> </table> </body> </html><editUser.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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>編輯用戶</title> </head> <body> <?php require_once 'inc/dbConn.php'; $userId=$_GET['id']; //這是啥東東。。 date_default_timezone_set("PRC"); //讀數據。。。 $sql = "select * from user where id=".$userId; $result = mysql_query($sql,$con); $user = mysql_fetch_array($result); ?> <form action="editDo.php" method="post"> <input type="hidden" name="user_id" value="<?php echo $user['id']?>"/> <table width="444" border="1" align="center"> <tr>