So I have an index.html with the following code below. I want to get the variable "variableFromMyPHPscript" into my index.html from my GetVariable.php file.
<!doctype html>
<html>
<head>
<meta charset = "utf-8">
</head>
<body>
<p>Random Text....</p>
</body>
</html>
<script>
console.log(variableFromMyPHPscript);
</script>
And here is my PHP script (GetVariable.php) which uses json to get a value from my database so that it can be stored as a variable.
<script>
var variableFromMyPHPscript = <?php
$link = mysqli_connect('....', '....', '....', '....');
$query = "select * from thunderDemo";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result))
{
if($row["ThunderOrNot"] == 'Thunder')
{
echo json_encode("Thunder1");
}
}
mysqli_close($link);
?>;
</script>
So how would I go about getting the value of "variableFromMyPHPscript" from my PHP file to my HTML file so that I can use it with the JavaScript within the HTML file? Thank you for any help!