AJAX Database: The PHP File

Book information will be listed here...
The page on the server called by the JavaScript is a PHP file called GetBook.php, which runs a query against a MySQL database, and returns the result in an HTML table. When the query is sent from the JavaScript to the PHP file, the following happens:
  1. PHP opens a connection to a MySQL server.

  2. The correct book is found.

  3. An HTML table is created, filled with data, and sent back to the txtHint placeholder.
<?php
  $username = "user.id@undcsmysql";
  $password = "your-password";
  $database = "your-database";
  $host     = "undcsmysql.mysql.database.azure.com";

  // Connect to the database.
  $conn     = new mysqli( $host, $username, $password, $database );
  if ( $conn->connect_error )
    die( 'Could not connect: ' . $conn->connect_error );

  // Print the table header.
  echo "<center><table border='1'><tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th></tr>";

  // Compose and execute a query.
  $q      = $_GET["q"];
  $sql    = "select * from bookList where ISBN = '" . $q . "'";
  $result = $conn->query( $sql );

  // Print the results row by row.
  if ( $result->num_rows > 0 ) {
    while ( $row = $result->fetch_assoc( ) ) {
      echo "<tr><td>" . $row['ISBN']  . "</td>";
      echo     "<td>" . $row['title'] . "</td>";
      echo     "<td>" . $row['price'] . "</td></tr>";
    }
  }
  echo "</table></center>";

  // Close the database connection.
  $conn->close( );
?>