一个设计 - 注册界面(一)
2017-09-18 00:27
190 查看
这里用的是MySQL+PHP基友组合
首先,我们需要创建一个数据库,并且创建user(id,name,pw)方便起见,我们将id设置为主键(默认)+自动增长
这里使用mysqli_connect,注意和mysql区别一下,确定连接成功之后,我们判断输入密码是否一致
判断用户名是否存在,mysqli_num_rows可以获取该用户名是否存在
把注册界面放进去
运行一下 输入错误密码 输入存在用户名
首先,我们需要创建一个数据库,并且创建user(id,name,pw)方便起见,我们将id设置为主键(默认)+自动增长
这里使用mysqli_connect,注意和mysql区别一下,确定连接成功之后,我们判断输入密码是否一致
$link = mysqli_connect('localhost', 'root', '你的数据库密码', '数据库名字');
<?php $link = mysqli_connect('localhost', 'root', '你的数据库密码', '数据库名字'); if (!$link) { die('Could not connect: ' . mysql_error()); }else { if (isset($_POST['submit'])){ if ($_POST['pw'] == $_POST['repw']){ //下面有说 }else { echo "<script>alert('两次输入密码不一致!')</script>"; } } } ?>
判断用户名是否存在,mysqli_num_rows可以获取该用户名是否存在
echo当然是调试用的(不用管啦)
$query = "select * from user where name = '{$_POST['name']}' "; $result=mysqli_query($link, $query); $num=mysqli_num_rows($result); if($num){ echo $num;//echo "<script>alert('存在!')</script>"; }else{ $query1 = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')"; $result1=mysqli_query($link, $query1); echo $result1; }
把注册界面放进去
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> <style> body{ background: black; } </style> </head> <body> <div style="width: 100px;height: 100px;background: url(../img/bg/reg.png);margin: 40px auto;"> </div> <form method="post" style="width: 300px;height: 390px;border: 1px solid white;margin: 0px auto;" action="存放php的地址"> <div style="width: 100px;height: 40px;margin-left: 40px;margin-top: 50px;"> <p style="color: white;text-align: center;">用户名 </p> </div> <input type="text" name="name" style="margin-left: 70px;"> <div style="width: 100px;height: 40px;margin-left: 40px;margin-top: 50px;"> <p style="color: white;text-align: center;">密码 </p> </div> <input type="password" name="pw" style="margin-left: 70px;"> <div style="width: 100px;height: 40px;margin-left: 40px;margin-top: 50px;"> <p style="color: white;text-align: center;margin-left: 30px;">再次确认 </p> </div> <input type="password" name="repw" style="margin-left: 70px;"> <br><br> <button type="submit" name="submit" style="margin-left: 125px;">确认</button> </form> </body> </html>
运行一下 输入错误密码 输入存在用户名
<?php $link = mysqli_connect('localhost', 'root', '', ''); if (!$link) { die('Could not connect: ' . mysql_error()); }else { if (isset($_POST['submit'])){ if ($_POST['pw'] == $_POST['repw']){ $query = "select * from user where name = '{$_POST['name']}' "; $result=mysqli_query($link, $query); if($result){ echo "<script>alert('存在!')</script>"; }else{ $Requery = "insert into user (name,pw) values('{$_POST['name']}','{$_POST['pw']}')"; } }else { echo "<script>alert('两次输入密码不一致!')</script>"; } } } ?>
相关文章推荐
- 编程设计一个登陆界面
- FastReport控件系列写一个小小报表界面设计工具
- 一个简单的Jsp注册界面
- DAO设计模式---实现一个简单的注册(中)
- 一个WEB系统的界面设计和开发 —— 一个经验级人物的文章
- EasyJWeb作为一个快速Java Web MVC框架,其设计目标不尽是要简化软件开发人员的代码书写工作,更是要能方便界面设计人员的工作。
- 一个 App 的界面设计流程是怎么产生的?
- 一个好的界面设计应该注意的 75 个原则
- JAVA之简单界面设计(布局,更改背景图片,按钮监听 + 数据库登陆注册相关..)
- winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)
- 推荐一个界面设计软件:Balsamiq Mockups!
- 用C#构建一个简单的采集系统之一-主界面设计
- 用C#设计一个简单的修改密码界面
- DAO设计模式---实现一个简单的注册(下)
- 一个小的注册界面demo
- 请问一下在xml注册界面做一个框,并且把代码生成的验证码显示到里面,谢谢了
- 界面设计:一个像素之差产生的距离(转)
- 【转】一个不错的Matlab的gui界面设计实例 (2008-10-03 15:47:30)matlab gui 界面 校园 分类:Matlab实例
- 注册界面设计及实现之(三)SharedPerferences实现数据暂存
- HTML网页设计每日笔记(给初学者的一份礼物) (自己做的一个邮箱界面)