?本文給大家分享的是使用php+mysql實(shí)現(xiàn)用戶的增刪改查功能的全部頁面代碼,非常的詳細(xì),也很實(shí)用,適合php的初學(xué)者,有需要的小伙伴參考下。
?
文件列表。。文件內(nèi)容。。
dbconn.php
userListt.php
editUser.php
editDo.php
detailUser.php
deleteUser.php
addUser.php
addDo.php
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
1 2 3 4 5 6 |
// 創(chuàng)建數(shù)據(jù)庫連接 $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'); ?> |
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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 |
|
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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']; //這是啥東東。。 date_default_timezone_set("PRC"); //讀數(shù)據(jù)。。。 $sql = "select * from user where id=".$userId; $result = mysql_query($sql,$con); $user = mysql_fetch_array($result); ?> |
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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; // 執(zhí)行sql語句 mysql_query($sql,$con); // 獲取影響的行數(shù) $rows = mysql_affected_rows(); // 返回影響行數(shù) // 如果影響行數(shù)>=1,則判斷添加成功,否則失敗 if($rows >= 1) { alert("編輯成功"); href("userListt.php"); }else{ alert("編輯失敗"); // href("addUser.php"); } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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"); //讀數(shù)據(jù)。。。 $sql = "select * from user where id=".$userId; $result = mysql_query($sql,$con); $user = mysql_fetch_array($result); ?>
|
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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 |
// 包含數(shù)據(jù)庫文件 require_once 'inc/dbConn.php'; // 獲取刪除的id $id = $_GET['id']; $row = delete($id,$con); if($row >=1){ alert("刪除成功"); }else{ alert("刪除失敗"); } // 跳轉(zhuǎn)到用戶列表頁面 href("userListt.php"); function delete($id,$con){ $sql = "delete from user where id='$id'"; // 執(zhí)行刪除 mysql_query($sql,$con); // 獲取影響的行數(shù) $rows = mysql_affected_rows(); // 返回影響行數(shù) return $rows; } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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 |
|
?
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
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; // 執(zhí)行sql語句 mysql_query($sql,$con); // 獲取影響的行數(shù) $rows = mysql_affected_rows(); // 返回影響行數(shù) // 如果影響行數(shù)>=1,則判斷添加成功,否則失敗 if($rows >= 1){ alert("添加成功"); href("userListt.php"); }else{ alert("添加失敗"); // href("addUser.php"); } function alert($title){ echo ""; } function href($url){ echo ""; } ?> |
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
請您花一點(diǎn)時間將文章分享給您的朋友或者留下評論。我們將會由衷感謝您的支持!
PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔(dān)心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號