<?php
	//echo "Hello World";
	$host="localhost" ;
	$database="players";
	$user="root";
	$password = "root";
	$error = "Cant connect";
	$con = mysqli_connect($host,$user,$password);
	mysqli_select_db($con, $database) or die("Unableto connect to database");
	$name = $_GET['name'];
	echo "name: ".$name;
	$score = $_GET['score'];
	$query = "SELECT * FROM high_scores WHERE name = '$name'";
	$result= mysqli_query($con, $query);
	$n = mysqli_num_rows($result);
	//if ($n > 0) echo "Found 1 record"; else echo "Sorry not registered";
	if ($n > 0)
	{
		echo "Found 1 record";	
		$query = "UPDATE high_scores SET score ='$score' WHERE name = '$name'";
	}  
	else 
	{
		echo "Sorry not registered";	
		$query = "INSERT INTO high_scores VALUES ('$name','$score')";
	}
	$result= mysqli_query($con, $query);
	/*$query = "SELECT * FROM high_scores";
	$result= mysqli_query($con, $query);
	$n = mysqli_num_rows($result);
	for ($i = 0; $i < $n; $i++)
	{
		$name = mysqli_fetch_assoc($result)["name"];
		$score = mysqli_fetch_assoc($result)["score"];
		echo $name."\t";
		echo $score."\n";

	}*/

?>
