Need help displaying database to HTML table

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? :frowning:

Welcome to the world of Database Interaction.

Please dont feel like i’m picking on you, but you’ve got quite a few things to adjust here.
#0: mysql as a library is being deprecated; you should look at moving to [FPHP]mysqli[/FPHP] or [FPHP]PDO[/FPHP].
#1: mysql_numrows is not a function ([FPHP]mysql_num_rows[/FPHP])
#2: Consider using a while construct that uses the result resource’s own pointer (while($row = [FPHP]mysql_fetch_assoc/FPHP) { )
#3: If you do #2, your $f definitions can be simplified using a list (list($f1,$f2,$f3,$f4) = $row)… or alternatively you can just use the $row variable in your echos (<?php [FPHP]echo[/FPHP] $row[‘gamename’]; ?>)
#4: If you’re doing this in a development area, you should consider turning error displays on (#1) until you get the script doing what it should be.