<?php

	/* Grab the URL variable */
	$acode = $_GET["acode"];
	$doy = $_GET["doy"];

	/* Connect to database and grab the keys */
		
$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 `acode2` FROM `acode3`";
	$result = $conn->query($query);
	$num=$result->num_rows;	



	
	/* Set up a loop to check if requested key is found in database */
	$i=0;
	$validationkey = 0;

	$validation = "";

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


	
	/* If a match was found in database, echo "VALID". Else echo "ERROR" */
	
	if($validation != "") {
	
	
		$result = $conn->query("SELECT * FROM acode3 WHERE acode2='{$acode}' ") 
		or die(mysql_error()); 
		
		

		while($row = mysqli_fetch_object($result))
		{
			$acode3 = $row->acode3;
		
	
			$code = 0;

			$code = $acode3;
		}
	}
	

	
	if($validation != "") 
	{
		if ($code == ($acode - 990000000) * 9) echo $code ;
		else if ($code != $acode) echo 111111 ;
	} 
	else 
	{
		echo 111111;
	}


?>