- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章PHP连接数据库实现注册页面的增删改查操作由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了php连接数据库实现注册页面的增删改查操作的方法,供大家参考,具体内容如下 。
1.连接数据库 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<?php
//本地测试
$host
=
'127.0.0.1'
;
$port
= 3306;
$user
=
"root"
;
$pwd
=
""
;
$link
= @mysql_connect(
"{$host}:{$port}"
,
$user
,
$pwd
,true);
if
(!
$link
) {
die
(
"connect server failed: "
. mysql_error());
}
//选择连接的数据库库名
mysql_select_db(
"my"
);
//设置字符编码utf8
mysql_set_charset(
'utf8'
);
?>
|
2.注册页面(html页面) 。
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
|
<!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"
xml:lang=
"en"
>
<head>
<meta http-equiv=
"content-type"
content=
"text/html;charset=utf-8"
/>
<title>document</title>
</head>
<body>
<h3>注册页面</h3>
<form action=
"add.php"
method=
'post'
>
<table border=
'1'
cellpadding=
'0'
cellspacing=
'0'
width=
'80%'
bgcolor=
'#abcdef'
>
<tr>
<td align=
'right'
>用户名</td>
<td><input type=
"text"
name=
"username"
id=
""
/>以小写字母开始,长度要求5~10</td>
</tr>
<tr>
<td align=
'right'
>密码</td>
<td><input type=
"password"
name=
"password"
id=
""
/>密码不能为空</td>
</tr>
<tr>
<td align=
'right'
>邮箱</td>
<td><input type=
"text"
name=
"email"
id=
""
/></td>
</tr>
<tr>
<td align=
'right'
>性别</td>
<td>
<input type=
"radio"
name=
"sex"
id=
""
value=
'1'
/>男
<input type=
"radio"
name=
"sex"
id=
""
value=
'2'
/>女
<input type=
"radio"
name=
"sex"
id=
""
value=
'3'
/>保密
</td>
</tr>
<tr>
<td align=
'right'
>个人简介</td>
<td>
<textarea name=
"txt"
id=
""
cols=
"50"
rows=
"10"
></textarea>
</td>
</tr>
<tr>
<td colspan=
'2'
><input type=
"submit"
name=
'act'
value=
'注册'
/></td>
</tr>
</table>
</form>
</body>
</html>
|
3.将注册数据显示在数据库 。
1
2
3
4
5
6
7
8
9
10
11
12
|
//往数据库中添加数据
<?php
header(
"content-type:text/html; charset=utf-8"
);
//-----------------------连接数据库---------------------------
include_once
"connect.php"
;
//-------------------------将数据连接到数据库------------------
$time
=time();
$sql
=
"insert into user (username,password,email,sex,txt,`time`) value('{$_post['username']}','{$_post['password']}','{$_post['email']}','{$_post['sex']}','{$_post['txt']}','{$time}')"
;
$res
=mysql_query(
$sql
);
header(
"location:hello.php"
);
?>
|
4.返回后台界面 。
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
|
<?php
header(
"content-type:text/html; charset=utf-8"
);
//-----------------------连接数据库------------------------------
include_once
"connect.php"
;
//--------------------查询数据库--------------------------------
$query
=
"select * from user"
;
$result
=mysql_query(
$query
);
if
(!
$result
)
{
die
(
"could not to the database<br/>"
.mysql_error());
}
//-------------------封装函数-----------------------------
//该函数将数据库的数据写成数组形式
function
result2arr(
$result
){
while
(
$result_row
=mysql_fetch_assoc(
$result
)){
$arr
[] =
$result_row
;
}
return
$arr
;
}
$arr
= result2arr(
$result
);
foreach
(
$arr
as
$key
=>
$value
){
echo
"<table border='1px'>"
;
echo
"<table border='1px' >"
;
echo
"<tr> "
;
echo
"<td width='100px'>"
.
$value
[
'id'
].
"</td>"
;
echo
"<td width='100px'>"
.
$value
[
'username'
].
"</td>"
;
echo
"<td width='100px'>"
.
$value
[
'password'
].
"</td>"
;
echo
"<td width='200px'>"
.
$value
[
'email'
].
"</td>"
;
echo
"<td width='100px'>"
.
$value
[
'sex'
].
"</td>"
;
echo
"<td width='100px'>"
.
$value
[
'txt'
].
"</td>"
;
echo
"<td width='100px'>"
.
date
(
'y-m-d h:i:s'
,
$value
[
'time'
]).
"</td>"
;
echo
"<td width='100px'><a href='update1.php?id=$value[id]'>修改</a> <a href='delete.php?id=$value[id]'>删除</a></td>"
;
echo
"<tr/>"
;
echo
"</table>"
;
}
?>
|
5.修改数据 。
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
|
//当用户要修改信息时,返回页面,页面中包含之前填写的信息
<!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"
xml:lang=
"en"
>
<head>
<meta http-equiv=
"content-type"
content=
"text/html;charset=utf-8"
/>
<title>document</title>
</head>
<body>
<div>
<?php
include_once
"connect.php"
;
$sql
=
"select * from user where id='"
.
$_get
['id
']."'
";
//echo "sql:".$sql;(显示出修改哪一行)
$result
=mysql_query(
$sql
,
$link
);
$arr
= result2arr(
$result
);
//print_r($arr);
$row
=
$arr
[0];
function
result2arr(
$result
){
while
(
$result_row
=mysql_fetch_assoc(
$result
)){
$arr
[] =
$result_row
;
}
return
$arr
;
}
?>
<h3>注册页面</h3>
<form action=
"update.php"
method=
'post'
>
<input type=
"hidden"
name=
"id"
id=
""
value=
"<?php echo $row['id']?>"
/>
<table border=
'1'
cellpadding=
'0'
cellspacing=
'0'
width=
'80%'
bgcolor=
'#abcdef'
>
<tr>
<td align=
'right'
>用户名</td>
<td><input type=
"text"
name=
"username"
id=
""
value=
"<?php echo $row['username']?>"
/>以小写字母开始,长度要求5~10</td>
</tr>
<tr>
<td align=
'right'
>密码</td>
<td><input type=
"password"
name=
"password"
id=
""
value=
"<?php echo $row['password']?>"
/>密码不能为空</td>
</tr>
<tr>
<td align=
'right'
>邮箱</td>
<td><input type=
"text"
name=
"email"
id=
""
value=
"<?php echo $row['email']?>"
/></td>
</tr>
<tr>
<td align=
'right'
>性别</td>
<td>
<input type=
"radio"
name=
"sex"
id=
""
value=
'1'
<?php
if
(
$row
[
'sex'
]==
'1'
){
echo
'checked'
;}?>/>男
<input type=
"radio"
name=
"sex"
id=
""
value=
'2'
<?php
if
(
$row
[
'sex'
]==
'2'
){
echo
'checked'
;}?>/>女
<input type=
"radio"
name=
"sex"
id=
""
value=
'3'
<?php
if
(
$row
[
'sex'
]==
'3'
){
echo
'checked'
;}?>/>保密
</td>
</tr>
<tr>
<td align=
'right'
>个人简介</td>
<td>
<textarea name=
"txt"
id=
""
cols=
"50"
rows=
"10"
><?php
echo
$row
[
'txt'
]?></textarea>
</td>
</tr>
<tr>
<td colspan=
'2'
><input type=
"submit"
name=
'act'
value=
'修改'
/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
//将修改的信息存入数据库
<?php
header(
"content-type:text/html; charset=utf-8"
);
//通过post获取页面提交数据信息
$data
=
$_post
;
//print_r($data);
include_once
"connect.php"
;
$sql
=
"update `user` set username='{$data['username']}',password='{$data['password']}', email='{$data['email']}',sex='{$data['sex']}',txt='{$data['txt']}' where id='{$data['id']}'"
;
echo
$sql
;
$res
= mysql_query(
$sql
,
$link
);
if
(
$res
){
header(
"location:hello.php"
);
//echo "alert('修改成功')";
}
else
{
header(
"location:update1.php?id="
.
$data
[
'id'
]);
//echo "alert('修改失败')";
}
?>
|
6.删除数据 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
//删除数据库里的数据
<?php
header(
"content-type:text/html; charset=utf-8"
);
include_once
'connect.php'
;
$sql
=
"delete from user where id='"
.
$_get
['id
']."'
";
$sus
=mysql_query(
$sql
,
$link
);
if
(
$sus
){
header(
"location:hello.php"
);
}
else
{
echo
"alert('删除失败')"
;
}
?>
//若要删除李四,点击删除后,会自动跳转到后台页面,数据库里数据也删除
|
以上就是本文的全部内容,希望对大家的学习有所帮助.
最后此篇关于PHP连接数据库实现注册页面的增删改查操作的文章就讲到这里了,如果你想了解更多关于PHP连接数据库实现注册页面的增删改查操作的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我有一个问题,想知道如何在已经使用常规登录/注册系统的网站上集成第 3 方登录(也进行静默注册)。 基本上当前登录还是比较规律的: 当用户进入网站 session 时类(class)决定他是否需要重新
我在学习 Hyperledger Fabric 并运行示例代码。 我仍在尝试正确了解事情的运作方式,尤其是在使用证书和加密 Material 的用户/管理员注册和注册中。 我想知道以下如何工作。 1)
我正在尝试使用从我的 Android 设备的 PassWallet 应用程序中保存的票证中获取的 token 向我的设备发送消息。 设备发送使用苹果钱包规范更新通行证所需的所有信息。但是,我正在使用
使用 Passport 本地示例,我可以登录工作。没有关于如何注册用户的文档。 我想为用户提供一个“电子邮件”和“密码”字段,他们可以使用它们来注册该网站。我怎样才能做到这一点?有什么原因没有记录下来
在之前的一些 WSO2IS 版本中,有一个默认的 self 注册功能。但是,我在 5.0 版本中找不到它。 阅读 WSO2IS 5.0 文档,我发现有 2 个用于此功能的 API: getUserId
我已将 Airship SDK 集成到 Android 应用程序中。在应用程序启动和飞艇起飞后,我在日志中得到以下调试信息: 07-27 12:46:31.916 XXX - UALib( 1545)
Delphi 中设计时包的可怕错误之一是以下错误,这意味着注册安装新组件到您的 Palette 上的包: Component TSomething can't be registered by pac
我发现的大部分内容都使用 php 或类似的东西。 我有一个 Angular 前端和 Node/express 服务器代码。还没有后端。我不确定如何继续用户注册。 最佳答案 在没有后端的情况下进行注册等
我正在使用 Drupal 6 开发一个网站。我正在使用我自己的主题,并且一切正常。现在我需要使用我的自定义主题在我的网站上创建一个自定义登录/注册表单。我尝试了很多方法,但一切都重定向到我的管理主题,
我在运行此代码时收到 Sip 异常。这是因为 manager.register(me,20,listener)。 下面是我的代码,所以请帮我更正这段代码。我正在使用 SipDemo 代码注册我的帐户。
在过去的几天里,我一直在尝试为基于 VUE 的 excel 制作任务 Pane 插件。 我已按照 link 的指南进行操作我试图为 onSelectionChange 注册一个事件处理程序。它已经有些
我需要在使用 django-registration 应用程序的登录表单中实现一个“记住我”按钮。任何ane可以帮助我向我展示这样做的方法吗? 谢谢 最佳答案 一种方法是更改 session 到期
我发现,如果您使用 Django 1.5 版本,则 django 注册模块会中断,因为在最新的 django 开发版本中,simple.py 类已被删除。 最佳答案 此问题现已修复: hg clone
我正在尝试将 facebook connect 实现到我的网站,但有几个问题。 1:是否可以使用用户当前的 Facebook 电子邮件/密码在我的网站上注册用户。 假设用户点击链接通过 faceboo
我使用 Facebook 注册来允许人们在我的网站上注册。有没有可能,在注册后,他在我的网站注册的成员(member)墙上会张贴? 最佳答案 这可能不是您正在寻找的答案,但我强烈建议您不要这样做。用户
I would like to use a slash (/) for a search during a vimscript, but I don't want to overwrite the "
我正在使用 jqgrid 并且有显示日期的列,但是来自服务器的日期以 json 格式出现,如下所示, "CommentedDate": "\/Date(1304324941000+0530)\/" 如
我希望用户可以直接登录主页,而不是在“../account/login/”页面上登录。我应该做什么才能使它成为可能?如何将主页上的输入字段与 allauth 连接?我不知道这样是否太复杂而无法以这种方
This question already has answers here: Understanding NSString comparison (7个答案) 5年前关闭。 我正在尝试制作注册表。有
我正在使用 Django 注册。它提供了处理 registration_form.html 的 View ,该 html 当前包含用户名、密码 1、密码 2 和电子邮件作为我的应用程序中的用户可输入字
我是一名优秀的程序员,十分优秀!