I have a page that is supposed to display some data fetched by AJAX from a database, but instead it displays an error message.
The page that shows the data:
<html>
<head>
<style type="text/css">
a {
text-decoration:none;
}
</style>
<script type="text/javascript">
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getinfo.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
//$niftystocks=array();
$sq="SELECT TPNTCode FROM `niftystock`";
$r=mysql_query($sq);
$i=0;
while ($ro=mysql_fetch_array($r)) {
//array_push($niftystocks,$row['TPNTCode']);
$tpnt=$ro['TPNTCode'];
$sql="SELECT * FROM `nsepricequotes_latest` where TickerPlantCode = '$tpnt' ";
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs);
if ($i == 0)
echo "--" . $row['DateTime'] . "--";
$sy=$row['Symbol'];
echo "<span id='txtHint'></span><a href='#'><span onmouseover='showUser()'>$sy</span>: " . $row['LastTradedPrice'] . " (" . $row['PercentChange'] . ")</a>";
if($row['PercentChange'] >= 0)
echo " <img src='http://mastertrade.in/master/ticker/images/arrow-up.gif' border='0' > | ";
else
echo " <img src='http://mastertrade.in/master/ticker/images/arrow-down.gif' border='0' > | ";
$i++;
}
?>
getinfo.php:
<?php
$q=$_GET['q'];
echo $q;
$con = mysql_connect('localhost', 'username', 'password');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);
$sql1="Select OpenPrice,HighPrice,LowPrice from nsepricequotes_latest WHERE Symbol like '".$q."' ";
while($row1= mysql_fetch_array($sql1)) {
$openprice=$row1['OpenPrice'];
$highprice=$row1['HighPrice'];
$lowprice=$row1['LowPrice'];
$tpnt=$row1['TickerPlantCode'];
}
$sql="SELECT * FROM 52wkhighlow WHERE nFTCode = '$tpnt'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$wkhigh=$row['BSE52WkHighVal'];
$wklow=$row['BSE52wlLowval'];
}
?>
<html>
<body>
<table>
<tr>
<td>Open Price</td><td><?php echo $openprice; ?></td>
<td>High Price</td><td><?php echo $highprice; ?></td>
<td>Low Price</td><td><?php echo $lowprice;?></td>
<td>52 Week High</td><td><?php echo $wkhigh;?></td>
<td>52 Week Low</td><td><?php echo $wklow;?></td>
</tr>
</table>
</body>
</html>
I'm getting this error:
-undefined Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mastertr/public_html/master/ticker/getinfo.php on line 11