title: Run AJAX PHP example in NetBeans
body: <p>I found what looks like a decent introductory tutorial on AJAX using PHP and MYSQL and followed it to the letter - this is my first attempt at AJAX and PHP and I wish to run this in NetBeans but don't know how to get it running.  How do I make this run in NetBeans?  I have set the main file to ajax.html and attempted to run using the Green arrow but when the HTML page appears it does nothing when I enter valid data and click the "Query MySQL" button</p>
  
  <p>Here us the ajax.html file</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;script language="javascript" type="text/javascript"&gt;
  &lt;!--
  // Browser support code
  function ajaxFunction(){
   var ajaxRequest;  // the variable that makes AJAX possible  
  try{
     // Opera 8.0+, Firefox, Safari
     ajaxRequest = new XMLHttpRequest();
  } catch(e){
  // internet explorer browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         } catch(e) {
         // something wrong in creating XMLHttpRequest
         alert("Browser didn't create XMLHttpRequest");
         return false;
         }
      }
  }
  
  // Now get the value from user and pass it to
  // server script
  var age = document.getElementById('age').value;
  var wpm = document.getElementById('wpm').value;
  var sex = document.getElementById('sex').value;
  
  var queryString = "?age=" + age;
  queryString += "&amp;wpm=" + wpm +"&amp;sex=" + sex;
  ajaxRequest.open("GET", "ajax-example.php" + queryString, true);
  ajaxRequest.send(null);
  }
  // --&gt;
  &lt;/script&gt;
  
  &lt;form name='myForm'&gt;
  &lt;br /&gt;
     Max Age: &lt;input type='text' id='age' /&gt; &lt;br /&gt;
  &lt;br /&gt;
     Max WPM: &lt;input type='text' id='wpm' /&gt;
   &lt;br /&gt;
  &lt;br /&gt;
  Sex: &lt;select id='sex'&gt;
  &lt;option value="m"&gt;m&lt;/option&gt;
  &lt;option value="f"&gt;f&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type='button' onClick='ajaxFunction()' value='Query MySQL' /&gt;
  &lt;/form&gt;
  &lt;div id='ajaxDiv'&gt;Your result will be displayed here&lt;/div&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the ajax-example.php file.  The MySQL on my machine appears to be "localhost3306" and using the port number 7777</p>
  
  <pre><code>&lt;?php
  
  $dbhost = "localhost3306:7777";
  $dbuser = "root";
  $dbpass = "password";
  $dbname = "web_prof_tracker";
  
  // Connect to MySQL server
  mysql_connect($dbhost, $dbuser, $dbpass);
  
  // Select database
  mysql_select_db($dbname) or die(mysql_error);
  
  // Retrieve the data from Query String
  $age = $_GET['age'];
  $sex = $_GET['sex'];
  $wpm = $_GET['wpm'];
  
  // Escape user input to help prevent SQL injection
  $age = mysql_real_escape_string($age);
  $sex = mysql_real_escape_string($sex);
  $wpm = mysql_real_escape_string($wpm);
  
  // Build query
  $query = "SELECT * FROM ajax_example WHERE sex = '$sex'";
  if(is_numeric($age))
      $query .= " AND age &lt;= $age";
  if(is_numeric($wpm))
      $query .= " AND wpm &lt;= $wpm";
  
  // Execute query
  $qry_result = mysql_query($query) or die (mysql_error());
  
  // Build result string
  $display_string = "&lt;table&gt;";
  $display_string .= "&lt;tr&gt;";
  $display_string .= "&lt;th&gt;Name&lt;/th&gt;";
  $display_string .= "&lt;th&gt;Age&lt;/th&gt;";
  $display_string .= "&lt;th&gt;Sex&lt;/th&gt;";
  $display_string .= "&lt;th&gt;WPM&lt;/th&gt;";
  $display_string .= "&lt;/tr&gt;";
  
  // Insert a new row in the table for each person returned
  while($row = mysql_fetch_array($sql_result)){
   $display_string = "&lt;tr&gt;";
   $display_string .= "&lt;td&gt;$row[name]&lt;/td&gt;";
   $display_string .= "&lt;td&gt;$row[age]&lt;/td&gt;";
   $display_string .= "&lt;td&gt;$row[sex]&lt;/td&gt;";
   $display_string .= "&lt;td&gt;$row[wpm]&lt;/td&gt;";
   $display_string .= "&lt;/tr&gt;";
  }
  echo "Query: " . $query . "&lt;br /&gt;";
  
  $display_string .= "&lt;/table&gt;";
   echo $display_string;
  ?&gt;
  </code></pre>