Ok, so let me first explain a couple of things before we get to the point. I'm creating a basic game where you got leaderboards and high scores. When you lose and the game is over, an input field will appear. And here you can type in your name and submit your high score.
And now my point is: How can I get the PHP-code to take the name and the high score that was submitted to my database. The high score is defined inside the Javascript code. Just in case if you wondering, the PHP code and the Javascript code is separated.
Here's how I tried to solve the problem, but it's definitely not working. PHP code only gets the name, and the high score it gets is apparently equal zero.
In the javascript inside a function I tried to use getElementById and then value:
document.getElementById("score").value = duck.highscore ;
<form method="post" action="index.php">
<input type="hidden" name="submitted" value="true">
<input type="text" name="score" id="score" value="">
<input type="text" id="nameInput" placeholder="your name" maxlength="12" name="name">
<input type="submit" id="submitted" value="Submit your highscore">
</form>
<?php
if (isset($_POST['submitted'])) {
// connect to the database
include('leaderboard.php');
$name = $_POST['name'] ;
$score = $_POST['score'] ;
$sqlinsert = "INSERT INTO leaderboard (name, score) VALUES ('$name','$score')" ;
if (!mysqli_query($conn, $sqlinsert)) {
die('error inserting new record') ;
} // end of my nested if statement
$newrecord = "record added" ;
} // end of main if statement
?>