Hello all, I am having a minor problem with this comments script I have. When I first wrote this up it was back in Feb and I haven't worked on it until now because I need to finish it for obvious reasons when you see it. Anyways, I can not remember what was wrong with it when I took a break from it. To my knowledge it was working fine. I have been validating all the code on the pages so I can launch this section to the rest of the site. When I validated it now it stopped working. When you type something in the text area and hit submit it doesn't submit the info. It just refreshes the a page and sends you back down to the form. The comment box is at the bottom of this page.
http://www.mesquitechristmas.com/local/display.php?id=61
What is really strange is this page has comments but when you first visit it they don't show unless you hit submit then they show. They use to show regardless. So it is connecting to the DB just not sure why it is not submitting....
http://www.mesquitechristmas.com/local/display.php?id=2
Here is the php for the comment field
// Start code for inserting comments
if(isset($_POST['timeout'])) {
if(time() < $_POST['timeout'])
unset($_POST);
$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
}
// 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)) {
$limit = 5;
{
$sql = "SELECT * FROM comments WHERE id = '$id' ORDER BY comment_date DESC";
$site['url'] = "http://www.mesquitechristmas.com/local/display.php?id=$id";
$PageNav = swPagination( $sql, $MRPP = $limit, $UriAdd = $site['url'], $SortByAllow = FALSE, $SortOrderSeed = FALSE );
$result = $PageNav['RowList']; #Don't think I need the stuff above
IF ( !$PageNav['TotalRes'] ) echo("<table class='fullbox' align='center' width='100%' cellpadding='1' cellspacing='1'><tr bgcolor='".$color."'>
<td align='left'>No Comments left for this Display. Be the first to leave one.</td></tr></table>");
$i = 0;
while ($row = mysql_fetch_array ($result)) {
$color = ($i%2== 0 || $i == 0)?'#F4F4F4':'#E4E4E4';
$id[$i] = $row["id"];
$firstname[$i] = $row["firstname"];
$location[$i] = $row["location"];
$comment_date[$i] = $row["comment_date"];
$comment[$i] = $row["comment"];
print"<table class='fullbox' align='center' width='100%' cellpadding='1' cellspacing='1'><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 colspan='4'><strong> Comment</strong>: $comment[$i]</td>
</tr></table>";
++$i;
}
}
}
print"<table width='100%'>
<tr>
<td> <div align='right'>$PageNav[HrefNav]</div></td>
</tr>
</table>";
}
// end code for displaying comments
Here is the HTML for the form and where it is displayed.
<table border='0' cellpadding='0' cellspacing='0' class='fullbox' width='100%'>
<tr>
<td class="title">Comments For <? echo $row['displayname']; ?>...</td>
</tr>
</table>
<?php show_data(); ?>
<a name="comments" id="comments">
<form method="post" action="display.php?id=<?php echo $row['id']."#comments"; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<table class="fullbox" border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>
<td></td>
</tr>
<tr>
<td width="203">Name: <input type="text" name="firstname" value="Anonymous" onclick="this.value=''" /></td>
<td width="287">Location: <input type="text" name="location" value="Anonymous" onclick="this.value=''" /></td>
</tr>
<tr>
<td colspan="2"><br />
Comment (Max 255 characters):<br />
<textarea name="comment" rows="5" cols="50" class="c5" onkeydown="javascript:limittext(this.form.comment);">
</textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="reset" value="Reset" /> <input type="submit" value="Submit" /></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img alt=" " border="0" height="7" src="/images/1pixel.gif" width="7" /></td>
<td class="shadow-mid" width="100%"><img alt=" " border="0" height="7" src="/images/1pixel.gif" width="7" /></td>
<td><img alt=" " border="0" height="7" src="/images/1pixel.gif" width="7" /></td>
</tr>
</table>
</form>
</a>
Any suggestion or ideas would be great as I am stumped. I think it has something to do with how the form is submitting but not sure as to what....
-Thanks