I have the following scenario running:
graph.html --> uses ChartJS to display a line graph and imports graph.js
<html>
<head>
<title>ChartJS - LineGraph</title>
</head>
<body>
<div class="chart-container">
<canvas id="mycanvas"></canvas>
</div>
<form name="form" action="" method="get">
<input type="text" name="input" id="subject" value="">
</form>
<!-- javascript -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/Chart.min.js"></script>
<script type="text/javascript" src="js/graph.js"></script>
</body>
graph.js --> makes a AJAX call on the graph.php file to get the data and format it.
$(document).ready(function(){
$.ajax({
url : "/graph.php",
type : "GET",
success : function(data){
console.log(data);
...
var LineGraph = new Chart(ctx, {
type: 'line',
data: chartdata
});
graph.php --> Calls mysql database to get data
$var = $_GET['input'];
$query = sprintf("SELECT $var FROM wetter");
//execute query
$result = $mysqli->query($query);
I like to change the SELECT statement in the php-file by entering a new SELECT-statement in a input field of the .html file. If I put the normal $_GET[] method into the .php it will not find the input value from the .html file.
How can I parse the input value from the .html to the .php when there is a Javascript file in between? Do I need to change something in my scenario?