PHP如何编写一个简单的用户注册表单验证示例代码?
- 内容介绍
- 文章标签
- 相关推荐
本文共计482个文字,预计阅读时间需要2分钟。
原文示例:
原文内容:本文实例讲述了PHP实现的用户注册表单验证功能。分享给大家供大家参考借鉴,具体如下:+ 注册界面 register.+h1 用户注册 /h1+ form method=post action=register_verify.php+ input type=text placeholder=用+ /form
改写内容:PHP用户注册验证功能示例。以下为注册页面代码:+ 注册页面 register.+h1 用户注册 /h1+ 表单 method=post action=register_verify.php+ 文本框 type=text placeholder=用户名+ /表单
本文实例讲述了PHP实现的用户注册表单验证功能。分享给大家供大家参考,具体如下:
注册界面
register.html
<h1>用户注册</h1> <form method="post" action="register_verify.php"> <input type="text" placeholder="用户名" name="username"><br><br> <input type="password" placeholder="密码" name="password"><br><br> <input type="password" placeholder="重复密码" name="password2"><br><br> <label>性别: <input type="radio" name="sex" value="男" checked="checked">男 <input type="radio" name="sex" value="女">女</label><br><br> <input type="email" placeholder="邮箱" name="email"><br><br> <button class="btn" type="submit">注册</button> </form>
register_verify.php
<?php require "mysql.php"; //导入mysql.php访问数据库 $username=$_POST['username']; $password=$_POST['password']; $password2=$_POST['password2']; $sex=$_POST['sex']; $email=$_POST['email']; if(checkEmpty($username,$password,$password2,$sex,$email)){ if(checkpwd($password,$password2)){ if(checkEmail($email)){ if(insert($username,$password,$sex,$email)) echo"注册成功"; } } } //方法:判断是否为空 function checkEmpty($username,$password,$password2,$sex,$email){ if($username==null||$password==null||$password2==null){ echo '<html><head><Script Language="JavaScript">alert("用户名或密码为空");</Script></head></html>' . "<meta tools.jb51.net/regex/javascript
正则表达式在线生成工具:
tools.jb51.net/regex/create_reg
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php程序设计安全教程》、《php安全过滤技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
本文共计482个文字,预计阅读时间需要2分钟。
原文示例:
原文内容:本文实例讲述了PHP实现的用户注册表单验证功能。分享给大家供大家参考借鉴,具体如下:+ 注册界面 register.+h1 用户注册 /h1+ form method=post action=register_verify.php+ input type=text placeholder=用+ /form
改写内容:PHP用户注册验证功能示例。以下为注册页面代码:+ 注册页面 register.+h1 用户注册 /h1+ 表单 method=post action=register_verify.php+ 文本框 type=text placeholder=用户名+ /表单
本文实例讲述了PHP实现的用户注册表单验证功能。分享给大家供大家参考,具体如下:
注册界面
register.html
<h1>用户注册</h1> <form method="post" action="register_verify.php"> <input type="text" placeholder="用户名" name="username"><br><br> <input type="password" placeholder="密码" name="password"><br><br> <input type="password" placeholder="重复密码" name="password2"><br><br> <label>性别: <input type="radio" name="sex" value="男" checked="checked">男 <input type="radio" name="sex" value="女">女</label><br><br> <input type="email" placeholder="邮箱" name="email"><br><br> <button class="btn" type="submit">注册</button> </form>
register_verify.php
<?php require "mysql.php"; //导入mysql.php访问数据库 $username=$_POST['username']; $password=$_POST['password']; $password2=$_POST['password2']; $sex=$_POST['sex']; $email=$_POST['email']; if(checkEmpty($username,$password,$password2,$sex,$email)){ if(checkpwd($password,$password2)){ if(checkEmail($email)){ if(insert($username,$password,$sex,$email)) echo"注册成功"; } } } //方法:判断是否为空 function checkEmpty($username,$password,$password2,$sex,$email){ if($username==null||$password==null||$password2==null){ echo '<html><head><Script Language="JavaScript">alert("用户名或密码为空");</Script></head></html>' . "<meta tools.jb51.net/regex/javascript
正则表达式在线生成工具:
tools.jb51.net/regex/create_reg
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php程序设计安全教程》、《php安全过滤技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

