I have been trying to figure why none of the JS I try to echo is echoing. To summarise my project I have a function which calls a PHP file and then the PHP file sends information back. It can send information which is not in JS but as soon as I try JS nothings come about. I have even tried a basic console.log(); and still nothing.
Does anybody have an idea on why this is?
Below is the file which is calling.
<html>
<link rel="stylesheet" type="text/css" href="styles.css">
<div class="HogMainContent">
<button name="Subtract" onclick=subtract()>Previous Game</button>
<button name="Add" onclick="add()">Next Game</button>
<div id="insertion"></div>
<script>
var count = 0;
function send(item) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
document.getElementById("insertion").innerHTML = this.responseText;
}
xmlhttp.open("GET", "gather.php?q=" + item);
xmlhttp.send();
}
function subtract() {
count--;
send(count);
}
function add() {
count++;
send(count);
}
</script>
</div>
</html>
Below is the file which is being called. This is where no JS is working.
<?php
$host = "localhost";
$username = "root";
$password = "";
$db = "ia2";
$link = mysqli_connect($host, $username, $password, $db);
if($link === false) {
die("Error: Couldn't Connect." . mysqli_connect_error());
}
$q = $_REQUEST["q"];
$sql = "SELECT * FROM vgsales WHERE `Rank`=$q";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result)>0) {
while($row=mysqli_fetch_array($result)){
echo $row['Rank'];
echo $row['Name'];
echo $row['Platform'];
echo $row['Year'];
echo $row['Genre'];
echo $row['Publisher'];
echo $row['NA_Sales'];
echo "
<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
<div id='myChart' style='width:100%; max-width:600px; height:500px;''></div>
<script type='text/JavaScript'>
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Sales Region', 'Number of Sales']
['NA Sales',". $row['NA_Sales']."],
['EU Sales',". $row['EU_Sales']."],
['France',". $row['JP_Sales']."],
['Spain',".$row['Other_Sales']."],
], true);
var options = {
title:'Game Sales". $row['Name']."'
};
var chart = new google.visualization.PieChart(document.getElementById('myChart'));
chart.draw(data, options);
}
</script>
";
}
mysqli_free_result($result);
}
}
else {
echo "Error: Could not execute $sql" . mysqli_error($link);
}
mysqli_close($link);
?>