De gemiddelde score berekenen lukt wanneer ik handmatig scores ingeef via mijn database (phpmyadmin). Het probleem is dat ik geen score kan invoeren in mijn database via mijn html/php bestand. Kan iemand mij even helpen?
Dit is mijn html bestand
<!DOCTYPE html>
<html>
<body>
<h2>Counter strike: GO</h2>
<form action="scoredropbox.php" method="POST">
<select name="score">
<h1>Score</h1>
<option value="score">score</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<input type="hidden" name="naamspel" value="1" />
<input type="submit" name="submit" value="Submit">
</form>
</select>
</body>
</html>
("naamspel" wordt gebruikt als het GameID.
GameID "1" is "Counter Strike: GO" in mijn database
Zo is GameID "2" bijvoorbeeld "Minecraft")
Dit is mijn php bestand
<?php
// Create connection
$con=mysqli_connect("localhost","root","", "games");
// Check connection
if ($con) {
$naamspel = 1;
$score = mysqli_real_escape_string($con, $_POST['score']);
$som=0;
$i = 0;
//gemiddelde score berekenen
$query = mysqli_query($con, "SELECT * FROM scores WHERE GameID='1'");
while($result = mysqli_fetch_assoc($query)){
$som = $som + $result['score'];
$i++;
}
echo round(($som/$i), 1);
//gekozen score invoegen
mysqli_query($con,"INSERT INTO scores (GameID, score)
VALUES ('$naamspel', '$score', )");
}
?>