Source code of dbFindAverageBad.php

<html>
<head>
<title>Find Average Item Price</title>
</head>
<body>
<h2>Find Average Item Price</h2>

<?php
  $lines 
file("mysql.txt");
  
$password trim($lines[0]);
  
$dbLink mysql_connect("localhost""tboegel"$password);

  
mysql_select_db("clearwater"$dbLink);

  
$query "SELECT inv_price FROM inventory";

  
$recordset mysql_query($query$dbLink);

  
$numberRows mysql_num_rows($recordset);
  
$sum 0;
  while(
$row mysql_fetch_assoc($recordset)) {
    
$sum += $row['inv_price'];
  }
  
$average $sum $numberRows;
  print 
"<p>The average price of items in our inventory is $average</p>";

?>
</body>
</html>