Location: PHPKode > projects > PHP MySQL Address Book > addressbook/main.php
<?php
require("sesionchk.php");
?>
<?php
require("links.php");
// like i said, we must never forget to start the session
session_start();

// is the one accessing this page logged in or not?
if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) {
	// not logged in, move to login page
	header('Location: index.php');
	exit;
}

?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>
<?php
require("title.php");
?>
</title>
</head>

<body>

<?php

$username="root";
$password="";
$database="addrnew";
$host="localhost";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT FirstName,EmailAddress FROM contacts limit 100";
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">First Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Email-Address</font></th>
</tr>

<?php


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
//$field1 = mysql_result($result,$row,"FirstName");
//$field2 = mysql_result($result,$row,"EmailAddress");

/*
while ($i < $num) {
$field1 = mysql_result($result,$i,"FirstName");
$field2 = mysql_result($result,$i,"EmailAddress");
*/
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $row["FirstName"]; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $row["EmailAddress"]; ?></font></td>
</tr>
<?php
//$i++;
}

echo "</table>";




?>



<p><a href="logout.php">Logout</a> </p>

</body>
</html>

Return current item: PHP MySQL Address Book