So I have discovered a method of transferring a JavaScript variable over to PHP (shown below):
<form name="submitForm" action="display2.php" method="post">
<input type="text" name="myValueResult" id="myValueResult" value="">
</form>
<?php
$result = $_POST['myValueResult'];
echo "<script>alert($result)</script>";
?>
<script>
let myValue = localStorage.getItem('Key'); (//This value came from a different page)
document.getElementById('myValueResult').value = myValue;
function something() {
document.submitForm.submit();
}
something()
</script>
Sorry if this method seems bad, I am not experienced with coding. But anyway PHP always gets to finish first which is not allowing JavaScript enough time to change the form input to it's variable value and is why PHP keeps alerting a blank number the first time but afterward it alerts the correct number but keeps looping the webpage.
Any feedback would be very much appreciated.