Jump to content

Adding comments


Boxerman

Recommended Posts

Hi all,

 

I've got a news table as such;

 

  `id` int(255) NOT NULL auto_increment,

  `title` mediumtext NOT NULL,

  `postedby` mediumtext NOT NULL,

  `text` mediumtext NOT NULL,

  `brief` mediumtext NOT NULL,

  `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,

  `image` varchar(255) NOT NULL default '',

  PRIMARY KEY  (`id`)

 

I was wondering in PHP how would i be able to add comments to the news?

 

i.e

 

Form: Name, IP (hidden), comments

I'll add the name, ip and comments to the database

 

But how do i go around adding that into php?

 

Link to comment
Share on other sites

Hi,

 

at the moment im using this:

 

/* create query */
$query = "SELECT * FROM news ORDER BY id DESC";
/* execute the query */
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$image = $row['image'];
$title = $row['title'];
$posted_by = $row['postedby'];
$brief = shorten_string($row['text'], $N);
?><p>

<table width="461" height="113" border=0">
  <tr>
    <th width="123" scope="col"><a href="news.php?id=<?PHP echo $row['id']; ?>"><img src="<?PHP echo $image; ?>" width="111" height="103" /></a></th>
    <th width="322" scope="col"><b><font size="5"><?PHP echo $title; ?></font></b> <br>
<font size="2">Posted By: <?PHP echo $posted_by; ?></font> <br><br>
</p><p><?PHP echo $brief; ?></p><p><b>
<a href="news.php?id=<?PHP echo $row['id']; ?>">Read More</a></b></p><br></th>
    
  </tr>

</table>
<?PHP
} 
?>

 

how would i add ontop that?

Link to comment
Share on other sites

create a new file called comments.php

 

 

then create a link from the main page to the comments page with the new id.

<?
/* create query */
$query = "SELECT * FROM news ORDER BY id DESC";
/* execute the query */
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$image = $row['image'];
$title = $row['title'];
$posted_by = $row['postedby'];
$brief = shorten_string($row['text'], $N);
?><p>

<table width="461" height="113" border=0">
  <tr>
    <th width="123" scope="col"><a href="news.php?id=<?PHP echo $row['id']; ?>"><img src="<?PHP echo $image; ?>" width="111" height="103" /></a></th>
    <th width="322" scope="col"><b><font size="5"><?PHP echo $title; ?></font></b> <br>
<font size="2">Posted By: <?PHP echo $posted_by; ?></font> <br><br>
</p><p><?PHP echo $brief; ?></p><p><b>
<a href="news.php?id=<?PHP echo $row['id']; ?>">Read More</a></b></p><p><b>
<a href="comment.php?id=<?PHP echo $row['id']; ?>">comment</a></b></p><br></th>
    
  </tr>

</table>
<?PHP
} 
?>

Link to comment
Share on other sites

Ok i'm starting to understand, but is there no way i can add the comments bit onto the news page itself?

 

I.e

 

News display here:

Title:

Story:

 

Leave a comment:

Name: textfield

Comment: textfield

Submit | Reset

 

Then post it to the database? and it automatically refreshes the page and displays comment?

 

If so, how on gods earth would i attempt this?

 

Cheers pal!

Link to comment
Share on other sites

You need a properly coded form with all of the information you wish to collect from the user, and the action set to the processing file.

 

Processing file checks the form parameters to make sure they are what you expect them to be.  Sanitizes the inputs so they will contain no database injection.  Inserts the data into a NEW database table, linking the comment to the news article by the news articles ID (primary key).  Then re-directs back to the news story page, which then calls the comments with a JOIN query, and displays them however you want to.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.