Maison  >  Article  >  php教程  >  php实现简单的注册系统

php实现简单的注册系统

PHP中文网
PHP中文网original
2016-05-25 17:06:381957parcourir

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>


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
);



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 "注册失败";
}
}
?>


Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn