You're not closing properly PHP
tag. And you can't mix HTML
markup together with PHP
code unless you echoing it. Consider this :
<?php
$host='localhost';
$username='';
$password='';
$database='reference';
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($database)or die("cannot select DB");
$sql="SELECT * FROM TestTable";
$result=mysql_query($sql); ?> //<-- close here
<table width="400" border="1" cellspacing="0" cellpadding="3">
<?php // <-- open here
while($rows=mysql_fetch_array($result)){ ?> //<-- close here
<tr>
<td width="30%"><?php echo $rows['firstname']; ?></td>
<td width="30%"><?php echo $rows['lastname']; ?></td>
<td width="30%"><?php echo $rows['gender']; ?></td>
<td width="30%"><?php echo $rows['console']; ?></td>
</tr>
<?php //<-- open here
} ?>
</table>
<?php
mysql_close();
//require_once 'Connection.php'; already connect using above connection
?>
And one more thing, mysql_*
extension are deprecated and you should used mysqli_*
or PDO
instead.
Mysqli version
<?php
// database connection
$con = mysqli_connect("localhost","","");
mysqli_select_db($con, "reference");
$get_data = "select * from `TestTable`";
$run_data = mysqli_query($con, $get_data);
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<?php // <-- open here
while ($rows=mysqli_fetch_array($run_data)) { ?>
<tr>
<td width="30%"><?php echo $rows['firstname']; ?></td>
<td width="30%"><?php echo $rows['lastname']; ?></td>
<td width="30%"><?php echo $rows['gender']; ?></td>
<td width="30%"><?php echo $rows['console']; ?></td>
</tr>
<?php //<-- open here
} ?>
</table>
<?php
mysqli_close();
?>
PDO version
<?php
// database connection
$con = new PDO('mysql:host=localhost;dbname=reference;charset=utf8', '', '');
$get_data = "select * from `TestTable`";
$run_data = $con->query($get_data);
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<?php // <-- open here
while ($rows = $run_data->fetch(PDO::FETCH_ASSOC)) { ?>
<tr>
<td width="30%"><?php echo $rows['firstname']; ?></td>
<td width="30%"><?php echo $rows['lastname']; ?></td>
<td width="30%"><?php echo $rows['gender']; ?></td>
<td width="30%"><?php echo $rows['console']; ?></td>
</tr>
<?php //<-- open here
} ?>
</table>