php简单注册代码nba买球:

作者:计算机教程

2、reg.php 注册文件(内有说明)

<form name="form1" method="post" action="regok.php" enctype='multipart/form-data' onsubmit="return checkreg()" >
  <table border="0" cellspacing="1" cellpadding="3" align="center">
    <tr>
      <th colspan="2"><font size="5">用 户 注 册 界 面</font></th>
    </tr>   
    <tr>
      <td>姓   名:</td>
nba买球,      <td>
        <input type="text" name="name">
    </tr>
    <tr>
      <td>密   码:</td>
      <td>
        <input type="password" name="password">       
    </tr>
 <tr>
      <td>确认密码:</td>
      <td>
        <input type="password" name="pwd">       
    </tr>
 <tr>
      <td>email:</td>
      <td>
        <input type="text" name="email">       
    </tr>
  <tr>
      <td>电   话:</td>
      <td>
        <input type="text" name="tel">
    </tr>
 <tr>
      <td>地   址:</td>
      <td>
        <input type="text" name="address">
    </tr>   
    <tr>
      <td  align=right >
        <input type="submit" name="submit" value="注 册">
      </td>
      <td align=center>
        <input type="reset" name="submit2" value="重 写">
      </td>
    </tr>
  </table>
</form>

return $objResponse;
}

 代码如下

http://blog.knowsky.com/

// 获得注册用户的自动id,以后使用此id才可登录
$result=mysql_query("select last_insert_id()",$conn);
$re_arr=mysql_fetch_array($result);
$id=$re_arr[0];

foreach($aFormValues as $key=>$value){
if (FunStringExist($value,$ArrFiltrate)){
$objResponse->addAlert("输入的信息含有非法字符"' ; union!"");
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
return $objResponse;
}
}

<script language="网页特效">
    function checkreg()
    {    
  if (form1.name.value=="")
  {
   // 如果真实姓名为空,则显示警告信息
         alert("真实姓名不能为空!");
   form1.name.focus();
   return false;
     }
  if (form1.password.value=="" )
  {
   // 如果密码为空,则显示警告信息
         alert("密码不能为空!");
   form1.password.focus();
   return false;
     }
  if (form1.pwd.value=="" )
  {
   // 如果密码为空,则显示警告信息
         alert("确认密码不能为空!");
   form1.pwd.focus();
   return false;
     }
  // 两次密码应一样
  if (form1.password.value!=form1.pwd.value && form1.password.value!="")
  {
   alert("两次密码不一样,请确认!");
   form1.password.focus();
   return false;
  }
  if (form1.email.value=="")
  {
   // 如果email为空,则显示警告信息
         alert("email不能为空!");
   form1.email.focus();
   return false;
     }
   // 检查email格式是否正确
  else if (form1.email.value.charat(0)=="." ||
   form1.email.value.charat(0)=="@"||
   form1.email.value.indexof('@', 0) == -1 ||
   form1.email.value.indexof('.', 0) == -1 ||
   form1.email.value.lastindexof("@")==form1.email.value.length-1 ||
   form1.email.value.lastindexof(".")==form1.email.value.length-1)
  {
   alert("email的格式不正确!");
   form1.email.select();
   return false;
  }
  return true;

<?php
function CheckEmailAddr($C_mailaddr)
{
if (!eregi("^[_a-z0-9-] (.[_a-z0-9-] )*@[a-z0-9-] (.[a-z0-9-] )*$",
$C_mailaddr))
{
return false;
}
return true;
}
//是否存在数组中的值
function FunStringExist($StrFiltrate,$ArrFiltrate){
foreach ($ArrFiltrate as $key=>$value){
if (eregi($value,$StrFiltrate)){
return true;
}
}
return false;
}
?>

 代码如下

复制代码 代码如下:

<html>
<body>

if (trim($usr) == "")
{
$errmsg.="请输入用户名!n";
}
if (trim($pwd) == "")
{
$errmsg.="请输入密码!n";
}
if ($pwd != $aFormValues['pwd2'])
{
$errmsg.="两次输入的密码不一致!n";
}

<?php

if (trim($usr) == "")
{
$errmsg.="请输入用户名!n";
}
if (trim($pwd) == "")
{
$errmsg.="请输入密码!n";
}
$sql="select * from zl_usr where zl_usr='$usr' and zl_pwd='$pw'";
$result=mysql_query($sql,$db);
if(!$myrow=mysql_fetch_array($result)){
$errmsg.="用户名不存在,或密码错误!n";
}
if ($errmsg=="")
{
$sForm = "登陆成功";
$objResponse->addAssign("formDiv","innerHTML",$sForm);
}
else
{
$objResponse->addAlert($errmsg);
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
}

</html>

点提交后执行singup.php里的processForm函数

// 注册成功,自动登录,注册session变量
session_register("user");
$user=$id;
echo "<table align=center><tr><td align=center>注册成功!</td></tr>";
echo "<tr><td align=center><font color=red>您的注册id是:".$id;
echo ",请您记住,以后用此id登录!</font></td></tr></table>";

复制代码 代码如下:

// 连接数据库,注册用户
$sql="insert into user(name, password, email, tel, address) values('$name','$password','$email', '$tel','$address')";
mysql_query($sql,$conn) or die ("注册用户失败: ".mysql_error());

<?php
$database="zl";//MYSQL数据库名
$db = mysql_connect("127.0.0.1", "root","123456");//MYSQL数据库用户名和密码
mysql_select_db($database,$db);
?>
function.php

    } 
</script>

foreach($aFormValues as $key=>$value){
if (FunStringExist($value,$ArrFiltrate)){
$objResponse->addAlert("输入的信息含有非法字符"' ; union!"");
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
return $objResponse;
}
}

//初始化session
session_start();
// 包含数据库教程连接文件和头文件
$conn=mysql教程_connect("localhost","phpdb","phpdb")
        or die("不能连接数据库服务器: ".mysql_error());
mysql_select_db("book",$conn) or die ("不能选择数据库: ".mysql_error());
?>
<?php
// 取得网页的参数
$name=$_post['name'];
$password=$_post['password'];
$email=$_post['email'];
$tel=$_post['tel'];
$address=$_post['address'];

function processForm($aFormValues)
{
$objResponse = new xajaxResponse();
require_once("conn.php");
$usr=$aFormValues['usr'];
$email=$aFormValues['email'];
$pwd=$aFormValues['pwd'];
$pw=Md5($pwd);
$errmsg="";
//要过滤的非法字符
$ArrFiltrate=array("'",";","union");

</body>

<?php
define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' );
//注意这里,必须要设置gb2312,不然中文会乱码
require_once("xajax.inc.php");
require_once("function.php");
$xajax = new xajax();
$xajax->registerFunction("processForm");
//同reg.php文件

// 加密密码
$password=md5($password);

另外下面是两个用到的文件代码 conn.php function.php
conn.php

<?php
require_once("inc/xajax.inc.php");
$xajax = new xajax("inc/login.php");
$xajax->registerFunction("processForm");
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="http://blogbeta.blueidea.com/css/style.css" _fcksavedurl=""http://blogbeta.blueidea.com/css/style.css"" type="text/css">
<title>无标题文档</title>
<?php $xajax->printJavascrīpt('inc/'); ?>
<scrīpt type="text/javascrīpt">
function submitSignup()
{
xajax.$('submitButton').disabled=true;
xajax.$('submitButton').value="http://blogbeta.blueidea.com/wait...";
xajax_processForm(xajax.getFormValues("signupForm"));
return false;
}
</scrīpt>
</head>
<body><form id="signupForm" action="javascrīpt:void(null);" ōnSubmit="submitSignup();">
<div id="main">
<div id="m1">用 户 登 陆</div>
<div id="formDiv">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right"> </td>
<td> </td>
</tr>
<tr>
<td width="31%" align="right">用户名:</td>
<td width="69%"><input name="usr" type="text" id="usr" />
*</td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input name="pwd" type="password" id="pwd" />
*</td>
</tr>

如果有错误信息则
$objResponse->addAlert($errmsg);
//弹出错误信息
$objResponse->addAssign("submitButton","value","继续");
$objResponse->addAssign("submitButton","disabled",false);
//修改submitButton这个按扭的属性

$xajax->processRequests();
?>

<?php
define ('XAJAX_DEFAULT_CHAR_ENCODING', 'gb2312' );
require_once("xajax.inc.php");
require_once("function.php");
$xajax = new xajax();
$xajax->registerFunction("processForm");

本文由nba买球发布,转载请注明来源

关键词: