<?php 
session_start();

include('config.php');

	$sitequery = 'select * from settings;';
	$siteresult = mysql_query($sitequery,$connection) or die(mysql_error());
	
	//Create site settings variables		
	$siteinfo = mysql_fetch_array($siteresult);
	$sitetitle = $siteinfo['title'];
	$siteurl = $siteinfo['url'];
	$logo = $siteinfo['logourl'];
	$statcode = $siteinfo['statcode'];


$username = $_POST['username'];
$email = $_POST['email'];
$password = md5($_POST['pWord']);
$fname = $_POST['fname'];

// Confirm username and email are not duplicates

$checkformembers = mysql_query("SELECT * FROM authors WHERE username = '".$username."'");

$checkforemails = mysql_query("SELECT * FROM authors WHERE email = '".$email."'");

if(mysql_num_rows($checkformembers) != 0){
	header('Location: login.php?error=user'); 
} elseif(mysql_num_rows($checkforemails) != 0){ 
	header('Location: login.php?error=email'); 
} else {

	$sql = "INSERT INTO authors VALUES ( NULL, 0, '".$email."', '".$username."', '".$password."', 
			'".$fname."', '".$fname."', NULL, NULL, 'http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=".$siteurl."/images/avatar.png&s=90', 0);";
	$query = mysql_query($sql);
	header('Location: login.php?account=new');
	exit();	
}


?>