Home > php教程 > PHP源码 > body text

php实现简单的注册系统

PHP中文网
Release: 2016-05-25 17:06:38
Original
2013 people have browsed it

php实现简单的注册系统

用户注册页面 reg.php

创建数据库  mydb.sql

PHP处理注册页面  regcheck.php

reg.php 用户注册页面

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户注册</title>
</head>
<body>
<form name="frm" method="post" action="checkreg.php">
<table width="31%" border="1" align="center">
  <tr>
    <td width="30%" height="35" align="right">用户名:</td>
    <td width="70%" height="35"><input type="text" name="name" /></td>
  </tr>
  <tr>
    <td width="30%" height="35" align="right">密码:</td>
    <td width="70%" height="35"><input type="password" name="password" /></td>
  </tr>
  <tr>
    <td height="35" colspan="2" align="center"><input type="submit" name="sub" value="提交" /></td>
  </tr>
</table>
</form>
</body>
</html>
Copy after login


mydb.sql 数据库

create database user;
use user;
create table yinfu(
userId int unsigned not null auto_increment primary key,
name varchar(20) not null,
password varchar(20) not null
);
Copy after login



checkreg.php php处理用户注册页面

<?php
//获取表单数据
$name=$_POST[&#39;name&#39;];
$password=$_POST[&#39;password&#39;];
$n=strlen($name);
$p=strlen($password);
if($n==0){
echo "请输入用户名";
}elseif(!($n>=5 && $n<=16)){
echo "用户名长度为5-16位";  
}elseif($p==0){
echo "请输入密码";
}elseif(!($p>=5 && $p<=16)){
echo "密码长度为5-16位";
}else{  
//连接数据库
$conn=mysql_connect("localhost","root","123456") or die("数据库连接失败");
//选择数据库
mysql_select_db("user");
//设置数据库编码
mysql_query("set names utf8");
//将表单获得的数据插入数据库
$sql="insert into yinfu(name,password)values(&#39;{$name}&#39;,&#39;{$password}&#39;)";
//执行sql 语句
mysql_query($sql);
//获得受影响的行数
$row=mysql_affected_rows($conn);
if($row>0)
{
  echo "注册成功";
}else{
   echo "注册失败";
}
}
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template