Jump to content


Making a Comment system


  • Please log in to reply
10 replies to this topic

#1 _*Hybrid Phire_*

_*Hybrid Phire_*
  • Guests

Posted 08 August 2004 - 05:03 PM

I need help with making a comment system for a news system I haev made, I know how to connect and post to databases, but I guess I just need help with showing certain comments in certain places. Any help you could offer would be good.

Thanks,

Hybrid Phire

#2 _*Dabu_*

_*Dabu_*
  • Guests

Posted 08 August 2004 - 07:55 PM

Here is what you gotta do. You gotta add an autoincreacing id for both the news (or whatever your adding comments to) and for the comments table. Then when somebody submits a comment grab the news posts unique ID and add it to a collum named postid or something like that. Then when you are retrivng the comments just run a query like

SELECT * FROM table WHERE postid='$POSTID'

Just replace the varialbes that need replacing.

#3 _*Hybrid Phire_*

_*Hybrid Phire_*
  • Guests

Posted 08 August 2004 - 09:39 PM

Ok, I figured it out before I came to read your reply, but thanks anyway!

#4 _*Hybrid Phire_*

_*Hybrid Phire_*
  • Guests

Posted 08 August 2004 - 11:06 PM

Ok, forget what I said, I need some assistance... I can get it to read fine, but I can't seem to get the posts to go into the mysql database

Heres the code I've got:
comments.php
<?php
include "config.php";
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Error! Could not connect to the databse");
$query = "SELECT name,subject,comment,date,news_id FROM news_comments WHERE news_id=$pageid";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
	$name=$r["name"];
	$subject=$r["subject"];
	$comment=$r["comment"];
	$date=$r["date"];
	$news_id=$r["news_id"];
	echo "
	<FONT face=Verdana size=1>
	<b>$subject</b><br>
	$comment<br>
	-Posted by $name on $date<hr>
	</font>";
	echo"
	<FORM name=\"post news comment\" action=process_news_comments.php?pageid=$news_id method=post>
	<P align=left>
	<FONT face=Verdana size=1>
	Name:<br><INPUT name=name><BR>
	Message Title:<br><INPUT name=subject><BR>
	Message:<br><TEXTAREA name=comment rows=6 cols=20></TEXTAREA>
	</FONT>
	</P>
	<input type=\"submit\" name=\"submit\" value=\"Post Comment!\">
	</FORM>";
}
mysql_close($db);
?>
process_news_comments.php
<?php
include "config.php";
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Error! could not connect to the databse!");
$query = "INSERT INTO news_comments(name,subject,comment,news_id,date)
VALUES('$_POST[name]','$_POST[subject]','$_POST[comment]','$_GET[$pageid],' now())";
mysql_query($query);
echo"Comment Added!";
mysql_close($db)
?>

Please reply if you can give me any assistance

#5 _*mYth_*

_*mYth_*
  • Guests

Posted 09 August 2004 - 01:43 AM

Alright mister, you listen and you listen good!!

When doing php, please I beg you PLEASE format it nicely, clean code makes easy reading....

Now Im going to take this stuff and see if I can solve your problem....

*mumbles* The things I do around here....

#6 _*mYth_*

_*mYth_*
  • Guests

Posted 09 August 2004 - 02:01 AM

Ok I dont usually do double posts, but I think this is a good exception.

Now it would help to see what your trying to do, I have no idea what you want but from the looks of it your trying to grab comment Ids from the url, right? ok well If you have a site I can help you out more.

If you want a option on how many comments to show heres a tip use MySQLs SHOW, you put it in your query like this...

SHOW 4

You can order it ASC or DESC anyway you want your choice.

Heres my update to it, please keep backups of what you have, I accept no responsibility for what it may do.

Process_news_comment.php
<?php
include "config.php";
// Swith the post vars to vars, extra step that doesnt need to be done, but lets do it anyway

$name = $_POST['name'];
$subject = $_POST['subject'];
$somment = $_POST['comment'];
$pageid = $_POST['pageid'];

$date = date('D, F jS Y - g:i A'); //Change this to what you want, I jsut added this

$db = mysql_connect($db_host,$db_user,$db_pass);

mysql_select_db ($db_name) or die ("Error! could not connect to the databse!");

$query = "INSERT INTO news_comments(name,subject,comment,news_id,date) VALUES('$name', '$subject', '$comment', 'NULL', '$date')";

mysql_query($query);

echo"Comment Added!";

mysql_close($db)

?>

comments.php
<?php

include "config.php";

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Error! Could not connect to the databse");

$query = "SELECT name,subject,comment,date,news_id FROM news_comments WHERE news_id=$pageid";
$result = mysql_query($query);

while($r=mysql_fetch_array($result))
     {
          $name = $r['name'];
          $subject = $r['subject'];
          $comment = $r['"comment'];
          $date = $r['date'];
          $news_id = $r['"news_id'];

          echo "<FONT face=Verdana size=1> <b>$subject</b><br> $comment<br>-Posted by $name on $date<hr></font>";
          echo"<FORM name=\"post news comment\" action=process_news_comments.php?pageid=$news_id method=post> <P align=left> <FONT face=Verdana size=1> Name:<br><INPUT name=name><BR> Message Title:<br><INPUT name=subject><BR> Message:<br><TEXTAREA name=comment rows=6 cols=20></TEXTAREA> </FONT> </P> <input type=\"submit\" name=\"submit\" value=\"Post Comment!\"> </FORM>";
     }

mysql_close($db);
?>

Look at my comments, the few that I made, you need to make sure that _POST vars are labeled with single quotes, and you need to work in methodical steps, and comment alot, it helps it really does.

Best of luck, let me know what happens, I would like to see this one run. Oh and I myself have a News Script that uses MySQL if you would want to look at it send me a PM..

#7 _*Dabu_*

_*Dabu_*
  • Guests

Posted 09 August 2004 - 07:23 AM

You didn't have to double post either youcould of editied it :-\. Post back here if that code works otherwise I will fix it for you.

#8 _*mYth_*

_*mYth_*
  • Guests

Posted 09 August 2004 - 01:48 PM

Yeah I know I could of done that, but i like to make a new post only If what I have to say is soemthing diffrent, if you want I can merge them both?

#9 _*Dabu_*

_*Dabu_*
  • Guests

Posted 09 August 2004 - 01:59 PM

Dosen't really matter im not an admin thats up to them to decide.

#10 _*Jaymz_*

_*Jaymz_*
  • Guests

Posted 09 August 2004 - 02:38 PM

I'm sure Faken will just look the other way this once :D

#11 Faken

Faken

    Pimpmaster G

  • Admin
  • 5,966 posts
  • Gender:Male
  • Location:Montreal, Canada

Posted 09 August 2004 - 02:47 PM

I'll call the nitpicking police... just wait here till they get here :D

Faken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users