php实现简单的注册系统
用户注册页面 reg.php
创建数据库 mydb.sql
PHP处理注册页面 regcheck.php
reg.php 用户注册页面
weenCompany闻名企业网站系统(免费开源)是一个功能强大, 使用简单的中英文企业智能建站系统, 您只需要一些基本的计算机知识就可以利用此系统完成中小型企业网站的建设; 是低成本企业网站架设方案之首选CMS系统, 也适合建设个人网站。weenCompany闻名企业网站系统功能:1. 程序代码简洁严谨, 整个系统程序仅2M左右大小.2. 中英文双语版共用一套网站程序, 双语页面实现自由切换.3
0
立即学习“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['name'];
$password=$_POST['password'];
$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('{$name}','{$password}')";
//执行sql 语句
mysql_query($sql);
//获得受影响的行数
$row=mysql_affected_rows($conn);
if($row>0)
{
echo "注册成功";
}else{
echo "注册失败";
}
}
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号