Hi,

Here is the code for a guest book sourced from php-mysql tutorial (http://www.php-mysql-tutorial.com/examples/guestbook/guestbook.php) to insert and view. The insert part is ok, but it cannot show the data.

<html><body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '123;

$dbname = 'mydb';
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ($dbname);
?>
<?php
$rowsPerPage = 10;
$pageNum = 1;
if(isset($GET['page']))
{
$pageNum = $
GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT id, name, email, url, message, DATE_FORMAT(entry_date, '%d.%m.%Y') "."FROM guestbook "."ORDER BY id DESC ". "LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed. ' . mysql_error());

if(mysql_num_rows($result) == 0)
{
?>
<p><br>
<br>Guestbook is empty </p>
<?php
}
else
{
while($row = mysql_fetch_array($result))
{
list($id, $name, $email, $url, $message, $date) = $row;

?>

<table width="550" border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="80" align="left"> <a href="mailto:<?=$email;?>" class="email">
<?=$name;?>
</a> </td>
<td align="right"><small>
<?=$date;?>
</small></td>
</tr>
<tr>
<td colspan="2">
<?=$message;?>
<?php

if($url != '')
{   
$url = "<a href='$url' target='_blank'>$url</a>";

?>
<br> <small>Homepage : <?=$url;?></small>
<?php
}
?>
</td>
</tr>
</table>
<br>
<?php
}

$query = "SELECT COUNT(id) AS numrows FROM guestbook";
$result = mysql_query($query) or die('Error, query failed. ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

$maxPage = ceil($numrows/$rowsPerPage);
$nextLink = '';

if($maxPage > 1)
{
$self = $_SERVER['PHP_SELF'];

$nextLink = array();

for($page = 1; $page <= $maxPage; $page++)
{
	$nextLink[] =  "<a href=\"$self?page=$page\">$page</a>";
}

$nextLink = "Go to page : " . implode(' &raquo; ', $nextLink);

}

mysql_close($conn);

?>
<table width="550" border="0" cellpadding="2" cellspacing="0">
<tr>
<td align="right" class="text">
<?=$nextLink;?>
</td>
</tr>
</table>
<?php
}
?>

Does anyone know the problem? As it does not show any query mistake.

Thanks for help

    Try adding the following to the start of the script, in order to see if PHP has any useful information to impart to you. (You can set display_errors to 0 later for the production version.)

    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL | E_STRICT);
    

    Also, to encourage myself and others to actually read your source code, please surround it with [noparse]

    ...

    [/noparse] tags so that the indenting is maintained, plus you'll also get color-coded syntax highlighting.

      Write a Reply...