Ok were back to square one since that last code jacked up my page so I had to revert back to the last working code. This code inserts the comments into that database and displays them on the page but visitor can refresh the page over and over again inserting the last comment made. I have been working with this for days trying everything and come up empty.
Here is as link where you can view this.
http://mesquitechristmas.com/local/display.php?id=2
Here is the code for the entire file.
<?php
// connect to database
include ('db_connect.php');
// start code for showing display information
if (isset($_GET['id'])) {
$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM users WHERE id = $id;";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$id = $row["id"];
$displayname = $row["displayname"];
$displaytype = $row["displaytype"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$postal = $row["postal"];
$country = $row["country"];
$rating = $row['rating'];
$votes = $row['votes'];
$imgurl = $row['imgurl'];
} else {
die("No user found");
}
} else {
die(mysql_error());
}
}
// end code for showing display information
// start code for displaying comments
function show_data(){
$id = array();
$firstname = array();
$location = array();
$comment_date = array();
$comment = array();
$id = mysql_real_escape_string($_GET['id']);
$i=0;
if(isset($id)) {
$sql = "SELECT * FROM comments WHERE id = $id;";
if($result = mysql_query($sql)) {
$i = 0;
while ($row = mysql_fetch_array ($result)) {
$color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE';
$id[$i] = $row["id"];
$firstname[$i] = $row["firstname"];
$location[$i] = $row["location"];
$comment_date[$i] = $row["comment_date"];
$comment[$i] = $row["comment"];
print"<tr bgcolor='".$color."'>
<td align='left' width='120'><strong> Name</strong>: $firstname[$i]</td>
<td align='left' width='120'><strong> Location</strong>: $location[$i]</td>
<td align='left' width='216'><strong> Date</strong>: $comment_date[$i]</td>
</tr>
<tr bgcolor='".$color."'>
<td class='commentBorder' colspan='4'><strong> Comment</strong>: $comment[$i]</td>
</tr>";
++$i;
}
}
}
}
// end code for displaying comments
// Start code for inserting comments
$firstname = $_POST['firstname'];
$location = $_POST['location'];
$comment_date = date("m-d-Y");
$comment = $_POST['comment'];
$id = $_POST['id'];
// setup our query
$query ="INSERT INTO comments (firstname, location, comment_date, comment, id) VALUES ('$firstname', '$location', '$comment_date', '$comment', '$id')";
$result=mysql_query($query) or die(mysql_error()); // run our query
// end code for inserting comments
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Mesquite Texas Country Christmas" />
<meta name="keywords" content="Mesquite, Texas, Country Christmas" />
<meta name="author" content="NA" />
<link rel="stylesheet" type="text/css" href="/stylesheet.css" media="screen" title="FBC" />
<script type="text/javascript" src="drop_down.js"></script>
<title>A Mesquite Country Christmas - <? echo $row['displayname']; ?></title>
</head>
<body>
<div id="wrap">
<a href="/index.html">
<img id="frontphoto" src="/images/header.png" width="760" height="237" alt="Mesquite Country Christmas" border="0"></a>
<div id="menu">
<h2 class="hide">Menu:</h2>
<ul id="avmenu">
<li><a href="/index.html">Home</a></li>
<li><a href="/christmasstory.html">The Christmas Story</a></li>
<li><a href="/directions.html">Directions</a></li>
<li><a href="#">Information</a><ul>
<li><a href="/information.html">Display Facts & Info</a></li>
<li><a href="/faq.html">FAQ</a></li>
<li><a href="/playlist.html">2008 Playlist</a></li>
<li><a href="#">Christmas History</a></li>
</ul></li>
<li><a href="#">Photos</a>
<ul>
<li><a href="/2007photos.html">2007</a></li>
</ul></li>
<li><a href="#">Videos</a>
<ul>
<li><a href="/2007videos.html">2007</a></li>
</ul></li>
<li><a href="/guestbook.php">Guestbook</a></li>
<li><a href="/webcam.html">Web Cam</a></li>
<li><a href="/webradio.html">Internet Radio</a></li>
<li><a href="http://www.noradsanta.org/" TARGET="_blank">Track Santa</a></li>
<li><a href="/projects.html">Projects & How Tos</a></li>
<li><a href="/links.html">Links</a></li>
<li><a href="/contact_us.html">Contact Us</a></li>
</ul>
<center><a href="http://www.toysfortots.org/" TARGET="_blank"><img src="/images/toys_for_tots.jpg" border="0" width="110" height="153" vspace="10"></a></center>
<center><a href="http://christmas.bronners.com/2007/house/534.html"><img src="http://christmas.bronners.com/voteforme/vote.jpg" border="0" width="110" height="153" alt="christmas decorations" vspace="10"></a></center>
</div>
<div id="content">
<div class="fadebox">
<h2><? echo $row['displayname']; ?></h2>
<hr />
<table align="center" border="0" cellpadding="0" cellspacing="0" width="550">
<tr>
<td align="center"><img src="<? echo $row['imgurl']; ?>" class="border" height="345" width="460"></td>
</tr>
<tr>
<td>
<table align="center"><tr><td>Rated 0 from 0 people | <b>Rate This</b>: <a href="displays.php?id=<?php echo $row['id']; ?>&rate=1">1</a> | <a href="displays.php?id=<?php echo $row['id']; ?>&rate=2">2</a> | <a href="displays.php?id=<?php echo $row['id']; ?>&rate=3">3</a> | <a href="displays.php?id=<?php echo $row['id']; ?>&rate=4">4</a> | <a href="displays.php?id=<?php echo $row['id']; ?>&rate=5">5</a>
</td><td> </td></tr></table></td></tr></table>
<table align="center" style="border-top: 1px solid #990000;" border="0" cellpadding="4" cellspacing="0" width="550">
<p><span class="title">About this Display...</span>
<tr><td class="bg2" width="100"><b>Display Name</b>:</td><td class="bg2"><? echo $row['displayname']; ?></td></tr><tr><td class="bg1"><b>Display Type</b>:</td><td class="bg1"><? echo $row['displaytype']; ?></td></tr><tr><td class="bg2"><b>Description</b>:</td><td class="bg2"><? echo $row['description']; ?></td></tr><tr><td class="bg1"><b>Address</b>:</td><td class="bg1"><? echo $row['address']; ?><br><? echo $row['city']. "," . $row['state']. " " . $row['postal']; ?><br><? echo $row['country']; ?><br><a href="http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=<? echo $row['address']; ?>&city=<? echo $row['city']; ?>&zipcode=<? echo $row['postal']; ?>&historyid=&submit=Get+Map" target="_NEW"><b>Get Directions</b></a></td></tr><tr><td class="bg2"><b>Website</b>:</td><td class="bg2"><a href="<? echo $row['website']; ?>" target="_blank"><? echo $row['website']; ?></a></td></tr><tr><td class="bg1"><b>Sponsor Links</b>:</td><td class="bg1">
<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//displays
google_ad_slot = "4239948836";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr></table></p>
<p><span class="title">Comments...</span><table align="center" style='border-top: 1px solid #990000' border="0" cellpadding="4" cellspacing="0" width="550">
<?php show_data(); ?>
</table></p>
<p><form method="POST" action="display.php?id=<?php echo $row['id']; ?>">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="550">
<tr>
<td>
<fieldset class="fieldset">
<legend class="legend"><strong>Leave A Comment</strong></legend>
<input type="hidden" name="id" value="<? echo $row['id']; ?>" />
Name: <input type="text" name="firstname" value="Anonymous" onClick="this.value=''"> Location: <input type="text" name="location" value="Anonymous" onClick="this.value=''"> <br>Comment (Max 255 characters): <br><textarea name="comment" rows="5" style="width: 500px;" onkeydown="javascript:limittext(this.form.comment);"></textarea>
<input type="submit" value="Submit"> <input type="reset" value="Reset"></fieldset></p></td></tr></table></form>
</div>
</div>
</div>
<div id="footer">
© 2007 Mesquite Country Christmas<br />
This site best viewed with <a href="http://www.spreadfirefox.com/node&id=0&t=219"><img border="0" alt="Firefox 2" title="Firefox 2" src="http://sfx-images.mozilla.org/affiliates/Buttons/firefox2/ff2b80x15.gif"/></a>
<br />
<br />
<script type="text/javascript"><!--
google_ad_client = "pub-8048181801684156";
//468x60, created 1/8/08
google_ad_slot = "0360766123";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</div>
</body>
</html>
-Thanks