Hello,
First thanks for the help! I am trying to learn how to use databases using MySQL. I have the database and table created, and the information is posting to the table, but I cannot get it to SELECT and print to the websites HTML table. Any help would be greatly appreciated. The entire project is three pages "guestbook.php, addguestbook.php, and viewguestbook.php" I did not include any of the code from the first two mentioned, only from viewguestbook.php as that is the only place I am having trouble. If you need a snippet from the others I will gladly produce. I have no errors being printed and it takes me to the viewguestbook.php page and shows the HTML table but does not show the data from the database table. Stumping to me but probably something simple.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>View Guestbook</title>
</head>
<body>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td>
</tr>
</table>
<br>
<?php
//Removed all references to connecting to DB and connecting to table since those are functional.
$sql = sprintf("SELECT * FROM $tbl_name", mysql_real_escape_string ($name), mysql_real_escape_string ($email),
mysql_real_escape_string ($comment), mysql_real_escape_string ($datetime));
$result=mysql_query("$sql");
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while ($rows=mysql_fetch_array($result, MYSQL_ASSOC));{
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td>ID</td>
<td>:</td>
<td><? printf($rows['id']); ?></td>
</tr>
<?php//Removed the rest of the table as it is redundant coding of the above TR
//remainder of php
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><? printf($rows['datetime']); ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?php
}
mysql_free_result($result);
mysql_close(); //close the database
?>
?>
Thanks again!
Warmaster