• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 简单的增删改查

php 搞代码 4年前 (2022-01-23) 27次浏览 已收录 0个评论

dbconn.php

<?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’);

?>

adduser.php

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

新增用户

<body>

用户名
密码
性别 男 女
年龄
出生年月

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1

2

3

4

5

6

7

8

9

10

11

12

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

爱好
个人简介

adddo.php

<?php

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 “<script type=’text/javascript’>alert(‘$title’);</script>”;

}

function href($url){

echo “<script type=’text/javascript’>window.location.href=’$url'</script>”;

}

?>

userlist.php

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>

会员信息列表

<body>

<?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 “

“;

}

?>

id 用户名 密码 性别 年龄 出生年月 爱好 注册时间 最后登录时间 操作
“.$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’]).”

delete.php

<?php

// 包含数据库文件

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 “<script type=’text/javascript’>alert(‘$title’);</script>”;

}

function href($url){

echo “<script type=’text/javascript’>window.location.href=’$url'</script>”;

}

?>

edituser.php

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

编辑用户

<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);

?>

“/>

用户名 />
密码 />
性别 <input type="radio" name="sex" value="男"

<?php if($user[sex]==’1′) echo “checked=\”checked\”” ?> /> 男

/> 女

年龄 />
出生年月

<?php

$birday_y=date(“Y”,$user[‘birthday’]);

$birday_m=date(“m”,$user[‘birthday’]);

$birday_d=date(“d”,$user[‘birthday’]);

?>

>1980

>1981

>1982

>1983

>1984

>1985

>1986

>1987

>1988

>1989

>1990

>1

>2

>3

>4

>5

>6

>7

>8

>9

>10

>11

>12

>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

爱好 />
个人简介

editdo.php

<?php

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 “<script type=’text/javascript’>alert(‘$title’);</script>”;

}

function href($url){

echo “<script type=’text/javascript’>window.location.href=’$url'</script>”;

}

?>

detailUser.php

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

查看用户明细

<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);

?>

%本文来源gaodai#ma#com搞*代#码9网#搞gaodaima代码

<!—ecms -ecms 亦可框起

–>

用户ID <?php echo $userId ?>
用户名 <?php echo $user[‘username’] ?>
密码 <?php echo $user[‘password’] ?>
性别 <?php if($user[sex]==’1′) echo “男”; else if($user[sex]==’2′) echo “女”; else “保密”; ?>

年龄 <?php echo $user[‘age’] ?>
出生年月

<?php

$birday_y=date(“Y”,$user[‘birthday’]);echo $birday_y.”年”;

$birday_m=date(“m”,$user[‘birthday’]);echo $birday_m.”月”;

$birday_d=date(“d”,$user[‘birthday’]);echo $birday_d.”日”;

?>

爱好 <?php echo $user[‘hobby’] ?>
个人简介 <?php echo $user[‘profile’] ?>
返回用户列表


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 简单的增删改查

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址