<?php
	
	
   
$random_token = md5(uniqid(rand(), true));
	

$con = mysql_connect("localhost","ooffle_tsm_admin","tsm12345");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("ooffle_tsmballoons", $con);
		//continue writing
		
		$sql2="INSERT INTO nametable (token,created_at)

			VALUES

			('$random_token',now())";



			if (!mysql_query($sql2,$con))

			  {

			  die('Error: ' . mysql_error());

			  }
		//echo "Record(s) added";
		//echo "<script type='text/javascript'>alert('Registration successful! Get ready for the game...');</script>";
	

















				//continue writing
//$result= mysql_query("SELECT COUNT(*) AS total FROM nametable WHERE token


		$getURLresult= mysql_query("SELECT randomURL FROM weblinktable WHERE id=1 ");

		while($rows = mysql_fetch_array($getURLresult))
		{
				//echo $rows['randomURL'];
			$currentFile = $rows['randomURL'];
			
		}



$currentFileFull = $currentFile   .".php";

$random_token = md5(uniqid(rand(), true));	
$newFileFull = $random_token.".php";


$sql2 = "UPDATE weblinktable SET randomURL = '".$random_token."' WHERE id = '1'";
				
if (!mysql_query($sql2,$con)){die('Error: ' . mysql_error());}

mysql_close($con);


//echo 'current file'.$currentFileFull;
//echo 'new file'.$newFileFull;

 //rename the file
      rename($currentFileFull,$newFileFull);





		//header("Location: ".  $newFileFull);
		//die();
	
?>


<?php
	
	echo '<form id="myForm" action="' . $newFileFull . '" method="post">';
    foreach ($_POST as $a => $b) {
        echo '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">';
    }
		 echo '<input type="hidden" name="token" value="'.$random_token .'">';
	echo '</form>';	

echo '<script type="text/javascript">';
echo 'document.getElementById("myForm").submit();';
echo '</script>';
    die();
?>
