Odd problem. The below code is part of a .php file that will display a certain text depending upon: index.php?resource=1/2/3, etc. (the actual code is in a separate file, included("")) I deciding to add a commenting system to it, using DBs. It ALMOST works, but for some strange reason if I post one comment then try to post a different one it comes up identical to the previous. I.e. if I commented once to say "This thing sucks", then changed my mind the next time my comment (no mater what I type) always says "This thing sucks". Not as in I'm trying to edit the previous one, a completely new comment. On the page to display them theres just the orig and nothing else. But the DB has multiple identical entries.
PHP Code:
<?php
$resource=$_GET['resource'];
$username=$_POST['username'];
$comment=$_POST['comment'];
include("../phpscripts/dbc.php");
$SQL=" SELECT * FROM comments ";
//$SQL = $SQL . " WHERE category = '$category' ";
$retid=mysql_db_query($db, $SQL, $cid);
if (!$retid) { echo( mysql_error()); }
else {
while($row = mysql_fetch_array($retid)) {
$username=$row['username'];
$comment=$row['comment'];
$comments="comments:
<br>
<br>
$username said: $comment";
}
}
if ($logged=="yes") {
if($_SERVER['REQUEST_METHOD']=="POST") {
$SQL=" INSERT INTO comments ";
$SQL=$SQL . " (username, resource, comment) VALUES ";
$SQL=$SQL . " ('$username', '$resource', '$comment') ";
$result=mysql_db_query($db,"$SQL",$cid);
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
}
$commentbox="Please use the below box to comment.
<br>
<br>
<form name=\"comment\" action=\"index.php?resource=$resource\" method=\"POST\">
<input name=\"username\" type=\"hidden\" value=\"$user\">
<textarea name=\"comment\" class=\"descr_field\">
</textarea>
<br>
<br>
<div class=\"button\">
<a href=\"#\" onClick=\"document.comment.submit();\">
Comment
</a>
</div>
</form>";
}
else {
$commentbox="You must be logged in to comment, please login of create an account.";
}
I hope I explained it right.
Thanks,
Tim
EDIT: Also there is more to the script but it repeats in this all the way down, just changed text:
PHP Code:
if ($resource=="1") {
$title="asdasd";
$path="asdasd";
$description="asdasdasdasd";
print("<div id=\"maintitlediv\">~whatever whatever $title
</div>
</div>
Details of $title.<br>
<br>
<img src=\"http://fassist.profusehost.net/images/public_images/images/$path.png\" alt=\"asd\">
<br>
<br>
<br>
$description
<br>
<br>
$comments
<br>
$commentbox");
die();
}
Bookmarks