Home > Article > Backend Development > PHP MYSQL implements user addition, deletion, modification and query_PHP tutorial
This article shares with you all the page codes for using PHP MYSQL to realize the user's addition, deletion, modification and query function. It is very detailed and very Practical and suitable for PHP beginners, please refer to it if you need it.
File list. . File content. .
dbconn.php
userListt.php
editUser.php
editDo.php
detailUser.php
deleteUser.php
addUser.php
addDo.php
?
|
<🎜>//Create 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');<🎜> <🎜>?> |
?
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 |
|
?
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 |
require_once 'inc/dbConn.php'; $userId=$_GET['id']; // This is 啥东东。。 date_default_timezone_set("PRC"); //read data... $sql = "select * from user where id=".$userId; $result = mysql_query($sql,$con); $user = mysql_fetch_array($result); ?> |
?
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 |
require_once 'inc/dbConn.php'; //////////////////// ///获取用户信息 //////////////////// $user_id = $_POST['user_id']; $user_name = $_POST['user_name']; $password= $_POST['password']; if($_POST['sex']=='男') { $sex=1; } else if($_POST['sex']=='女') { $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); $hobby = $_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',hobby='$hobby',profile='$profile' where id='$user_id'"; echo $sql; // 执行sql语句 mysql_query($sql,$con); // 获取影响的行数 $rows = mysql_affected_rows(); // 返回影响行数 // 如果影响行数>=1,则判断添加成功,否则失败 if($rows >= 1) { alert("编辑成功"); href("userListt.php"); }else{ alert("编辑失败"); // href("addUser.php"); } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
?
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 |
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); ?>
|
?
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 |
// 包含数据库文件 require_once 'inc/dbConn.php'; // 获取删除的id $id = $_GET['id']; $row = delete($id,$con); if($row >=1){ alert("删除成功"); }else{ alert("删除失败"); } // 跳转到用户列表页面 href("userListt.php"); function delete($id,$con){ $sql = "delete from user where id='$id'"; // 执行删除 mysql_query($sql,$con); // 获取影响的行数 $rows = mysql_affected_rows(); // 返回影响行数 return $rows; } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
?
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 |
|
?
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 |
require_once 'inc/dbConn.php'; //////////////////// ///获取用户信息 //////////////////// $user_id = $_POST['user_id']; $user_name = $_POST['user_name']; echo $user_name; $password= $_POST['password']; if($_POST['sex']=='男') { $sex=1; } else if($_POST['sex']=='女') { $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); $hobby = $_POST['hobby']; $profile = $_POST['profile']; $addTime=mktime(date("h"),date("m"),date("s"),date("m"),date("d"),date("Y")); $lastLoginTime=$addTime; $sql = "insert into user (username,password,sex,age,birthday,hobby,profile,add_time,last_login) ". "values('$user_name','$password','$sex','$age','$birthday','$hobby','$profile','$addTime','$lastLoginTime')"; echo $sql; // 执行sql语句 mysql_query($sql,$con); // 获取影响的行数 $rows = mysql_affected_rows(); // 返回影响行数 // 如果影响行数>=1,则判断添加成功,否则失败 if($rows >= 1){ alert("添加成功"); href("userListt.php"); }else{ alert("添加失败"); // href("addUser.php"); } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
以上所述就是本文的全部内容了,希望大家能够喜欢。
请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!