Jump to content

[SOLVED] comments display?


freebsdntu

Recommended Posts

Hi, I am quite a newbie in php, I am trying to write a comments system in php, you know, like the add comment functionality in msn space.

I have done with the forms, quite simple form with just nickname and comment, and I know how to get the form input from user in php. Now the problem is how do I display the newly posted message? Like the one in msn space? I guess to achieve that, I have to modify the page, I have thought of using dom approach, but what if the form page is a php page, not html page? Ad there is no dom -> loadPHPFile() function.

I wish you guys can figure out what i am trying to explaining. All hints are greatly appreciated! Thank you very much!

Link to comment
Share on other sites

thank you for your kind reply,but after fetching it, how do I display it?

Ok, there is a document called comments.php, in which the form is included, there is also a document called addmessage.php, which does the logic, what I am thinking of is there is a header("Location:comments.php") statement at the end of addmessage.php, which means that user will be redirected back to the addmessage.php page, and the comment he has just posted would appear in the addmessage.php, very much like the behavior of my space add comment functionality, right?

So my problem is how do I insert the message posted to addmessage.php document.

Link to comment
Share on other sites

well you need to try this yourself,

dont expect us to do all the work,

i myself was once a "noob" at PHP so I will

get you started,

first off you need to store all your comments in

a MySQL database, then simply do this

(modify script with your details!)

 

<?php
$host = 'localhost'; // MySQL Host
$username = 'username'; // Username
$password = 'password'; // Password
$db = 'database'; // Database

$conn = mysql_connect($host, $username, $password);
mysql_select_db($db, $conn);

// Edit the following line
$query = mysql_query("SELECT * FROM your_table DESC");

while($row = mysql_fetch_array($query)){
echo '
Posted By: '.$row['nickname'].'<br>
Comment:<br>
'.$row['comment'].'<br>'."\n";
}

mysql_close($conn);

?>

Link to comment
Share on other sites

thank you for your help,northern rock.

I know how to do the database stuff,for your code,when you echo the data from mysql,where would it go?I guess it would go to the addmessage.php,right?What I would like to achieve is to echo the data to message.php,the page where the add message form is in.

Anyway,I would try it and see.

Link to comment
Share on other sites

thank you for your help,northern rock.

I know how to do the database stuff,for your code,when you echo the data from mysql,where would it go?I guess it would go to the addmessage.php,right?What I would like to achieve is to echo the data to message.php,the page where the add message form is in.

Anyway,I would try it and see.

 

isnt northern rock a bank that went bust???

 

think his name is northern flame :P

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.