<?php


	$email = $_POST["email"];
	$serial = $_POST["serial"];
	$real1 = $_POST["real1"];
	$real2 = $_POST["real2"];
	
echo $email;
echo $serial;

echo $real1;
echo $real2;


$servername = "localhost";
$username = "u9cwxhx7pzvxt";
$password = "Maggie@2014SG$2014%%";
$dbname = "phibase0_servequant";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 


	$query = "SELECT `acode` FROM `acode`";

	$result = $conn->query($query);
	$num=$result->num_rows;	
	

	$i=0;
	$validationkey = 0;

	$validation = "";

if ($result=mysqli_query($conn,$query))
{
	while ($obj=mysqli_fetch_object($result))
	{
		if ($serial == $obj->acode)
		{
			$validation = "Success";
		}
	}
	mysqli_free_result($result);
}	
	

if ($validation == "")
{

	if ($serial != 0)
	{
		$conn->query("INSERT INTO acode(acode, email) VALUES('$serial', '$email')") or 
		die("Could not INSERT acode TO database");
		
		$code = ($serial - 990000000) * 9;

		$conn->query("INSERT INTO acode3(acode2, acode3) VALUES('$serial', '$code')") or 
		die("Could not INSERT acode TO database");			
		
	}
}
else
{
	echo "Activation code Order already Registered. ";

}	



	
	if ($real1 != 0)
	{

		$conn->query("INSERT INTO real1(acode, real1) VALUES( $serial, $real1)") or 
		die("Couldnt INSERT REAL1 TO database");
	}


	if ($real2 != 0)
	{

		$conn->query("INSERT INTO real2(acode, real2) VALUES( $serial, $real2)") or 
		die("Couldnt INSERT REAL2 TO database");
	}
	
	echo "Account Registration Successful";


	
	$conn->close();


?>

