title: Returns Undefined Instead Of Value
body: <p>I have a page that is supposed to display some data fetched by AJAX from a database, but instead it displays an error message.</p>
  
  <p>The page that shows the data:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;style type="text/css"&gt;
      a {
          text-decoration:none;
      }
      &lt;/style&gt;
      &lt;script type="text/javascript"&gt;
      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 &amp;&amp; xmlhttp.status==200) {
                  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
              }
          }
          xmlhttp.open("GET","getinfo.php?q="+str,true);
          xmlhttp.send();
      }
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;?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 "&lt;span id='txtHint'&gt;&lt;/span&gt;&lt;a href='#'&gt;&lt;span onmouseover='showUser()'&gt;$sy&lt;/span&gt;: " . $row['LastTradedPrice'] . " (" . $row['PercentChange'] . ")&lt;/a&gt;";
            if($row['PercentChange'] &gt;= 0)
                echo " &lt;img src='http://mastertrade.in/master/ticker/images/arrow-up.gif' border='0' &gt; | ";
            else
                echo " &lt;img src='http://mastertrade.in/master/ticker/images/arrow-down.gif' border='0' &gt; | ";
            $i++;         
        }
      ?&gt;
  </code></pre>
  
  <p>getinfo.php:</p>
  
  <pre><code>&lt;?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']; 
  }  
  
  ?&gt;
  &lt;html&gt;
    &lt;body&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td&gt;Open Price&lt;/td&gt;&lt;td&gt;&lt;?php echo $openprice; ?&gt;&lt;/td&gt;
          &lt;td&gt;High Price&lt;/td&gt;&lt;td&gt;&lt;?php echo $highprice; ?&gt;&lt;/td&gt;
          &lt;td&gt;Low Price&lt;/td&gt;&lt;td&gt;&lt;?php echo $lowprice;?&gt;&lt;/td&gt;
          &lt;td&gt;52 Week High&lt;/td&gt;&lt;td&gt;&lt;?php echo $wkhigh;?&gt;&lt;/td&gt; 
          &lt;td&gt;52 Week Low&lt;/td&gt;&lt;td&gt;&lt;?php echo $wklow;?&gt;&lt;/td&gt; 
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <blockquote>
    <p>-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</p>
  </blockquote>