<?php
	session_start();
?>
<?php
	$x="join";
	$_SESSION['x']=$x;
	

$connect= @mysql_connect("localhost", "root", "") or die("Couldn't connect to the server.");
				mysql_select_db("scorerecord") or die("Database not found.");
				
$result=mysql_query("SELECT * from joingame");
$numrows=mysql_num_rows($result);
$gname=$_POST['gamename'];



if($_POST['submit']){
	if($_POST['gamename']=="Select A Game Name")
	{
		$msgs="Please select a game";
	}
	else{

		$result2=mysql_query("SELECT puzzlenames from joingame WHERE gamenames='$gname'");
		$fetch=mysql_fetch_assoc($result2);
		$varia=$fetch['puzzlenames'];
		$_SESSION['pname']=$varia;
		$_SESSION['gname']=$gname;
		
		header('Location: joinstart.php');
		exit;
	}
}



?>
	
<!DOCTYPE html> 
<html>
<head> 
	<title>Browser Mobile Sudoku</title> 
	<link rel="stylesheet" href="jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.css" />
	<script src="jquery-1.6.2.js"></script>
	<script src="jquery.mobile-1.0b2/jquery.mobile-1.0b2.min.js"></script> 
	
	
</head> 
<body> 
	<div data-role="page" id="Multiplayer">
		<div data-role="header" >
			<a href="multiplayer.html" data-icon="back">Back</a>
			<h1>Multiplayer</h1>
		</div>
		<div>&nbsp;</div>	
		<div align="center"><a>List of Created Games</a></div>	
		<div>&nbsp;</div>
		<form name="test" action="join.php" method="POST">
		<?php
		
		echo "<div align=\"center\">";
		echo "<font color=\"red\">";
		echo $msgs;
		echo "</font>";
		echo "</div>";
		
		echo $varia;
		echo"<div align = \"center\">";
		echo " <select name=\"gamename\" data-theme=\"b\" data-native-menu=\"false\">";
			echo "<option value=\"Select A Game Name\">Select A Game Name</option>";
			while($row=mysql_fetch_assoc($result))
			{
				$gamenames=$row['gamenames'];
				$puzzlenames=$row['puzzlenames'];
				echo "<option value=\"$gamenames\">$gamenames</option>";				
			}
		
			echo "</select>";
		echo "</div>"
		
		?>
		<input type="submit" name="submit" value="JOIN ME"  data-theme="c" data-transition="pop"/>	
		</form>
		
		
		<div data-role="footer" data-theme="a" data-position="fixed"> 
			<h1></h1> 
		</div>
	</div>
	
	
		<!-- ****************** -->
		<div>&nbsp;</div>	
		<div data-role="footer" data-theme="a" data-position="fixed"> 
			<h1></h1> 
		</div>
	</div>
</body>
</html>