Although, this is such a simple question, but I still cannot figure it out. I'm working on a PHP file that is used to get some data from my database and then store it in a jSON string variable $result. I tried to get some value from my select option value element in my HTML using $_POST, and used it in my query. But, unfortunetly, it didn't work. No data stored in my array variable. 'namgi' & 'notrafo' is my select element's name that i will be used in the query.
this is my php code [getdata.php]:
<?php
$server= "localhost";
$user="root";
$pass="";
$namagis=($_POST['namgi']);
$notrafos=($_POST['notrafo']);
$con = mysql_connect($server,$user,$pass);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("data", $con);
$query = mysql_query("SELECT * FROM `ukur` WHERE NamaGI=\"$namagis\" && NoTrafo=$notrafos");
$bS = array();
$bS['name'] = 'Beban S';
$bT = array();
$bT['name'] = 'Beban T';
while($r = mysql_fetch_array($query)) {
$bS['data'][] = $r['BebanS'];
$bT['data'][] = $r['BebanT'];
}
$result = array();
array_push($result,$bS);
array_push($result,$bT);
print json_encode($result, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
The $result variable above, will be used in my Highchart script function. the script
$.getJSON("getdata.php", function(json) {
options.series[0] = json[0];
options.series[1] = json[1];
chart = new Highcharts.Chart(options);
});
My HTML Code
<html>
<head>
<!-- script here -->
</head>
<body>
<form id="choosegrafik" action="grafconnect.php">
<select id="namgi">
<option value="">Choose..</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select id="notrafo">
<option value="">Choose..</option>
<option value="A">a</option>
<option value="B">b</option>
</select>
<input id="submitgrafik" type="submit" value="Buka Grafik" />
</form>
</body>
</html>
I have searched the solutions in the internet, but still cannot figure it out. A beginners problem :D, So, I hope anyone could help me out. Thanks.,
$_POST['namgi']to$_POST['namgis']and$_POST['notrafo']to$_POST['notrafos']? However, without seeing the html, this is just a guess. Also, posting the database schema would help, too.