So im trying to build a simple game where a user tries to guess a random number.
The problem i am having is that each time i submit the form the page is refreshing so the random number is changing.
From reading other posts on $_SERVER['PHP_SELF'] i thought it should not refresh the page solely the input value.
But each time i submit the form, my random number changes.
Is there a way to submit the form and to not refresh the page.
<?php
function form(){
echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . ">";
echo "<input type='text' name='user' /><br/>";
echo "<input type='submit' value='submit' />";
}
form();
$userinput = $_POST['user'];
$random = rand ( 1 , 4);
echo "input is " . $userinput . " " . "random number is " . $random;
?>