require_once("util/config.php");
require_once("util/conn.inc.php");
require_once("util/function_util.php");
unset($err_msg_email);
$ChkInsert = true;
if (!empty($email)){ # Insert to DB
	
	$fname  		= trim($fname);
	$lname  		= trim($lname);
	$email 		= trim($email);
	$pwd 			= trim($pwd);
	$location 	= trim($location);
	$nation 		= trim($nation);
	$gender 		= trim($gender);
	$edu 			= trim($edu);
	$age 			= trim($age);
	$comment 	= trim($comment);
	
	$sql = "select * from MEMBER where memail = '$email'";
	$result = mysql_query($sql);
	
	if (mysql_num_rows($result)){
		$ChkInsert = false;
		$err_msg_email  = "$email isn't available.
";
	}
	
	if ($ChkInsert){ # insert Database
		
		$mid = md5(uniqid(rand()));
		$mregis_date = date("YmdHi");
		$sql   = "insert into MEMBER (mid, mfname, mlname, memail, mpwd, mlocation, mnation, ";
		$sql  .= "mgender, medu, mage, mcomment, mstatus, mregis_date) values('$mid', '$fname', '$lname', ";
		$sql  .= "'$email', '$pwd', '$location', '$nation', '$gender', '$edu', '$age', '$comment', 'A', '$mregis_date')";
		mysql_query($sql);
		mysql_close($db);
		
		header("Location: register_thankyou.html");
	}
}
##########################################  Select Location  ##########################################
unset($opt_location);
$sql  = "select lid, l_txt from LOCATION order by lid";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	if ($row['lid'] == "TH"){
		$opt_location .= "\n";
	}
	else{
		$opt_location .= "\n";
	}
}
##########################################  Select Gender  ##########################################
unset($opt_gender);
$sql  = "select gid, g_txt from GENDER order by gid";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	if ($row['gid'] == "1"){
		$opt_gender .= "\n";
	}
	else{
		$opt_gender .= "\n";
	}
}
##########################################  Select EDUCATION  ##########################################
unset($opt_edu);
$sql  = "select eduid, edu_txt from EDUCATION order by eduid";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	if ($row['eduid'] == "3"){
		$opt_edu .= "\n";
	}
	else{
		$opt_edu .= "\n";
	}
}
#########################################  Select AGE  ##########################################
unset($opt_age);
$sql  = "select arid, ar_txt from AGE_RANGE order by arid";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	if ($row['arid'] == "5"){
		$opt_age .= "\n";
	}
	else{
		$opt_age .= "\n";
	}
}
mysql_close($db);
?>