用php协注册页面,为实现在点击注册时将填写数据导入我建的数据库中,下面是我的代码,怎么修改?
<?php$select=mysql_connect('localhost','root','')ordie(mysql_error());mysql_select_db...
<?php
$select=mysql_connect('localhost','root',' ') or die(mysql_error());
mysql_select_db('users',$select);
session_start();
$form = ob_get_clean();
$GLOBALS['TEMPLATE']['title'] = "注册";
//第一次进入该页时显示的注册表单
if (!isset($_POST['submitted']))
{
$GLOBALS['TEMPLATE']['content'] = $form;
}
// 填写注册信息
else
{
// 验证密码
$password1 = (isset($_POST['password1'])) ? $_POST['password1'] : '';
$password2 = (isset($_POST['password2'])) ? $_POST['password2'] : '';
$password = ($password1 && $password1 == $password2) ? sha1($password1) : '';
// 验证码验证
$captcha = (isset($_POST['captcha']) && strtoupper($_POST['captcha']) == $_SESSION['captcha']);
// 输入正确则增加一项用户信息
if ($password &&
$captcha &&
User::validateUsername($_POST['username']) &&
User::validateEmailAddr($_POST['email']))
{
// 保证用户不是已经存在的
$user = User::getByUsername($_POST['username']);
if ($user->userId)
{
$GLOBALS['TEMPLATE']['content'] = '<p align="center" class="c1">该号已经被注册过!</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;
}
else
{
// 创建一个用户
$u = new User();
$u->userid=$_POST['userid'];
$u->username = $_POST['username'];
$u->password = $_POST['password1'];
$u->sex=$_POST['usersex'];
$u->emailAddr = $_POST['useremail'];
//$token = $u->setPending();
//将新注册的用户插入到数据库中
mysql_query("insert into zhuce(id,name,password,sex,email_address)
VALUES ('$u->userid','$u->username','$u->password','$u->sex','$u->emailAddr';");
exit; //在每个重定向之后都必须加上“exit",避免发生错误后,继续执行。
}
}
/*else // 数据无效
{
$GLOBALS['TEMPLATE']['content'] .= '<p align="center" class="c1">你的输入有误!</p> <p align="center" class="c1">请正确填写你的信息以方便我们为您注册!</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;
}*/
}
?> 展开
$select=mysql_connect('localhost','root',' ') or die(mysql_error());
mysql_select_db('users',$select);
session_start();
$form = ob_get_clean();
$GLOBALS['TEMPLATE']['title'] = "注册";
//第一次进入该页时显示的注册表单
if (!isset($_POST['submitted']))
{
$GLOBALS['TEMPLATE']['content'] = $form;
}
// 填写注册信息
else
{
// 验证密码
$password1 = (isset($_POST['password1'])) ? $_POST['password1'] : '';
$password2 = (isset($_POST['password2'])) ? $_POST['password2'] : '';
$password = ($password1 && $password1 == $password2) ? sha1($password1) : '';
// 验证码验证
$captcha = (isset($_POST['captcha']) && strtoupper($_POST['captcha']) == $_SESSION['captcha']);
// 输入正确则增加一项用户信息
if ($password &&
$captcha &&
User::validateUsername($_POST['username']) &&
User::validateEmailAddr($_POST['email']))
{
// 保证用户不是已经存在的
$user = User::getByUsername($_POST['username']);
if ($user->userId)
{
$GLOBALS['TEMPLATE']['content'] = '<p align="center" class="c1">该号已经被注册过!</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;
}
else
{
// 创建一个用户
$u = new User();
$u->userid=$_POST['userid'];
$u->username = $_POST['username'];
$u->password = $_POST['password1'];
$u->sex=$_POST['usersex'];
$u->emailAddr = $_POST['useremail'];
//$token = $u->setPending();
//将新注册的用户插入到数据库中
mysql_query("insert into zhuce(id,name,password,sex,email_address)
VALUES ('$u->userid','$u->username','$u->password','$u->sex','$u->emailAddr';");
exit; //在每个重定向之后都必须加上“exit",避免发生错误后,继续执行。
}
}
/*else // 数据无效
{
$GLOBALS['TEMPLATE']['content'] .= '<p align="center" class="c1">你的输入有误!</p> <p align="center" class="c1">请正确填写你的信息以方便我们为您注册!</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;
}*/
}
?> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询