So I’m trying to display a database in a HTML table using HTML and PHP to show the results. I’m a novice with PHP and trying to get the following to work:
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
</head>
<body>
<form action="insert.php" method="post">
Game Name: <input type="text" name="gamename">
Genre: <input type="text" name="genre">
Metacritic Score: <input type="text" name="score">
Completed?: <input type="text" name="completed">
<input type="submit">
<input type="reset">
</form>
<?php
$username="dbelldes_dbell";
$password="removed";
$database="dbelldes_jos2";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Games";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
?>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Game Name</th>
<th>Genre</th>
<th>Metacritic Score</th>
<th>Completed?</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"gamename");
$f2=mysql_result($result,$i,"genre");
$f3=mysql_result($result,$i,"score");
$f4=mysql_result($result,$i,"completed");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
</body>
</html>
I’m not sure what the problem is?