This article will share with you all the Page code for adding, deleting, modifying, and querying users using PHP + MYSQL, which is very detailed and practical and suitable for beginners of php, for more information, see. File List .. File Content ..
Dbconn. php
UserListt. php
EditUser. php
EditDo. php
DetailUser. php
DeleteUser. php
AddUser. php
AddDo. php
<? Php // create a database connection $ 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');?>
Member Information List
| Id |
User Name |
Password |
Gender |
Age |
Date of birth |
Hobbies |
Registration Time |
Last Logon Time |
Operation |
<? Phprequire_once 'inc/dbConn. php'; // What is this .. Date_default_timezone_set ("PRC"); // read data... $ SQL = "select * from user order by id asc"; $ result = mysql_query ($ SQL, $ con); $ userList = ''; while ($ rs = mysql_fetch_array ($ result) {$ userList [] = $ rs;} // loop user list foreach ($ userList as $ user) {echo"
| ". $ User ['id']." |
". $ User ['username']." |
". $ User ['Password']." |
". $ User ['sex']." |
". $ User ['age']." |
". Date (" Y-m-d ", $ user ['birthday'])." |
". $ User ['hobby']." |
". Date (" Y-m-d ", $ user ['add _ time'])." |
". Date (" Y-m-d ", $ user ['last _ login'])." |
Add & nbsp Delete & nbsp Change & nbsp check |
";}?>
Edit user<? Php require_once 'inc/dbConn. php'; $ userId = $ _ GET ['id']; // What is this .. Date_default_timezone_set ("PRC"); // read data... $ SQL = "select * from user where id =". $ userId; $ result = mysql_query ($ SQL, $ con); $ user = mysql_fetch_array ($ result);?>
<? Phprequire_once 'inc/dbConn. php '; ////////////// /// // $ user_id = $ _ POST ['user _ id']; $ user_name = $ _ POST ['user _ name']; $ password = $ _ POST ['Password']; if ($ _ POST ['sex'] = 'male') {$ sex = 1;} else if ($ _ POST ['sex'] = 'female ') {$ sex = 2;} else $ sex = 3; $ age = $ _ POST ['age']; $ birthday_y = $ _ POST ['birthday _ y']; $ birthday_m = $ _ POST ['birthday _ m']; $ birthday_d = $ _ POST ['birthday _ d']; $ birthday = mktime (0, 0, 0, $ birthday_m, $ birthday_d, $ birthday_y); $ holobby =$ _ POST ['hobby']; $ profile =$ _ POST ['profile ']; $ addTime = mktime (date ("h"), date ("m"), date ("s"), date ("m"), date ("d "), date ("Y"); $ lastLoginTime = $ addTime; $ SQL = "update user set username = '$ user_name', password = '$ password ', sex = '$ sex', age = '$ age', birthday =' $ birthday', holobby = '$ hoby ', profile = '$ profile' where id = '$ user_id' "; echo $ SQL; // execute the SQL statement mysql_query ($ SQL, $ con ); // obtain the number of affected rows $ rows = mysql_affected_rows (); // return the number of affected rows. // if the number of affected rows is greater than or equal to 1, the value is successfully added, otherwise, if ($ rows> = 1) {alert ("edited successfully"); href ("userListt. php ");} else {alert (" Edit failed "); // href (" addUser. php ");} function alert ($ title) {echo"