<?php
include '../comm/conn.php';
include '../comm/config.php';
include '../comm/checkpostandget.php';
session_start();
$tjr=$_SESSION["tjrid"];
$name=$_POST['username'];
$pwd=$_POST['adminpass'];
$email=$_POST['demail'];
$uquestion=$_POST['dquestion'];
$uanswer=$_POST['danswer'];
if($name==""||$pwd=="")
{
    header('Location: ../comm/error.php?err=0');
    exit;
}

$link = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$link) {
     die('数据库链接出错: ' . mysql_error());
}
mysql_select_db($dbname);

mysql_query("set names gbk");
//检查用户名是否被注册
$q = "SELECT * FROM user where ddusername='".$name."'";

$rs = mysql_query($q);
$num = mysql_num_rows($rs);
$sql2="select * from websetting where id=1";
	mysql_select_db($dbname);
	$rs2 = mysql_query($sql2);
	while ($row2 = mysql_fetch_array($rs2))
	{
	    $zzfl=$row2[zzfl]; 
	}
	$zzfl=floatval($zzfl);
if($num)
{
	header('Location: ../comm/error.php?err=1');
	exit;
}
//用户名可用，注册用户
else
{
    mysql_query("set names gbk");
	$pwd=md5($pwd);
	$sj= date("Y-m-d H:i:s");
	$insert = "INSERT INTO user(ddusername,ddpassword,email,regtime,lastlogintime,loginnum,tjr,yjs,uquestion,uanswer) values ('$name','$pwd','$email','$sj','$sj','1','$tjr','$zzfl','$uquestion','$uanswer')";
	mysql_query($insert);
	$tg=$tgbl*100;
	$fx=$fxbl*100;
	$cc="尊敬的".$name."您好:欢迎注册".$webtitle.",凡是通过".$webtitle."在淘宝购物的交易记录，都将享受到".$fx."%成交额的返现，推广其他用户，即可获取被推广用户返现额的".$tg."%的推广佣金，推广越多挣钱越轻松。祝您购物愉快！也欢迎您把我们的网站告诉更多的淘宝买家，谢谢！";
	$insert = "INSERT INTO msg(ddusername,title,content,addtime) values ('$name','欢迎注册$webtitle','$cc','$sj')";
	mysql_query($insert);
	$_SESSION["username"] = $name; 
	header('Location: regok.php');
}     

mysql_close($link);

?>
