正文:
给大家分享一个简单的PHP实现注册教程:
<?php
/*
* 建表SQL语句
*
*create table emp_user(
id int unsigned auto_increment primary key,
user_name varchar(10) not null unique,
password char(32) not null,
email varchar(40) not null
)charset=utf8;
*
*
*
*/
?>
<html>
<head>
<title>用户注册</title>
<script type="text/javascript">
function checkInput(form) {
var user_name;
user_name = form.user_name;
if(user_name.value == '')
{
alert('不能为空!');
return false;
}
var email = document.getElementById('email');
if(email.value == '')
{
alert('能为空!');
return false;
}
if(document.forms[0].password.value == '')
{
alert('能为空');
return false;
}
var pwd = form.password;
var pwd_2 = document.getElementById('password_2');
if(pwd.value != pwd_2.value)
{
alert('不一致!');
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" method="post" action="./t206.php" onsubmit="return checkInput(this);">
<h2></h2>
<p>:<input type="text" name="user_name" id="user_name"></p>
<p>:<input type="text" name="email" id="email"></p>
<p>:<input type="password" name="password" id="password"></p>
<p>:<input type="password" name="password_2" id="password_2"></p>
<p><input type="submit" name="register" id="register" value="注册" style="width: 150px;"></p>
<p><input type="reset" value="重新填写" style="width: 150px;"></p>
</form>
</body>
</html>
<?php
header('Content-type:text/html;charset=utf-8');
//判断点击按钮
if(isset($_POST['register']))
{
echo "<hr>";
$user_name = $_POST['user_name'];
$email = $_POST['email'];
$password = $_POST['password'];
//连接数据库
$connect = mysqli_connect('localhost','root','mysql123','test');
if(!$connect)
?>
由于篇幅有限,上面的只是代码的一部分,完整版代码在:wwwfe.lanzouv/i8OcB02gdmdc
更多推荐
PHP教程之实现用户注册实例
发布评论