无为清净楼资源网 Design By www.qnjia.com
本文实例为大家分享了PHP连接数据库实现注册页面的增删改查操作的方法,供大家参考,具体内容如下
1.连接数据库
<"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'); "htmlcode"><!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.将注册数据显示在数据库
//往数据库中添加数据 <"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"); "text-align: center">4.返回后台界面
<"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"; echo "<tr/>"; echo "</table>"; } "text-align: center">5.修改数据
//当用户要修改信息时,返回页面,页面中包含之前填写的信息 <!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> <"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; } "update.php" method='post'> <input type="hidden" name="id" id="" value="<"/> <table border='1' cellpadding='0' cellspacing='0' width='80%' bgcolor='#ABCDEF'> <tr> <td align='right'>用户名</td> <td><input type="text" name="username" id="" value="<"/>以小写字母开始,长度要求5~10</td> </tr> <tr> <td align='right'>密码</td> <td><input type="password" name="password" id=""value="<"/>密码不能为空</td> </tr> <tr> <td align='right'>邮箱</td> <td><input type="text" name="email" id="" value="<"/></td> </tr> <tr> <td align='right'>性别</td> <td> <input type="radio" name="sex" id="" value='1' <"radio" name="sex" id="" value='2' <"radio" name="sex" id="" value='3' <"txt" id="" cols="50" rows="10"><"submit" name='act' value='修改' /></td> </tr> </table> </form> </div> </body> </html>//将修改的信息存入数据库 <"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".$data['id']); //echo "alert('修改失败')"; } "text-align: center">6.删除数据
标签:PHP,数据库,注册页面
无为清净楼资源网 Design By www.qnjia.com广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com无为清净楼资源网 Design By www.qnjia.com暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 国风大师纯音系列《古筝仙子 常静演奏 十指弹一》1CD[FLAC][919MB]
- DasKapital-OneMustHaveChaosInsidetoGiveBirthtoaDancingStar(2024)[24-44.1]WAV
- 王菲.1999-《只爱陌生人》日本东芝版[低速原抓WAV+CUE]
- 张小英1987-金奖金曲第一集[新加坡版][WAV+CUE]
- 鹿晗.2015-重启【海蝶】【FLAC分轨】
- 张芸京.2012-小女孩【金牌大风】【WAV+CUE】
- 余天.2002-雄狮魅力金曲2CD(南方金点系列)【南方】【WAV+CUE】
- 银霞.1982-《结·SAYYESMYBOY》台湾复刻版[WAV+CUE]
- 梁汉文1993-火热动感[引进版][WAV+CUE]
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】