Jump to content

users write comments on a page


blackandwhite

Recommended Posts

Hi everyone, im new on here and its about time i found a big busy php forum like this. i have little knowledge in php and mysql but i let me tell you what i am trying to do and maybe some could help me.

i am loading some video clips for a youth club onto a website. Each video clip will have a page of its own. Now ive already done that but i need to allow the people who view the videoclip to add a comment about the video below it without having to log in.

So a php script is what i think will do the job. There will be a button titled "Add comment" or "Add review" and 2 fields for the user to enter name and comments in.

Well something along these lines anyway.

Could someone please advise me on how this could be accomplished, if not point me in the rightful direction. Any help would be extremly helpful for im not that skilled in php yet :-[

Keep up the excellent work.
thank you very much for your help and time.
Link to comment
https://forums.phpfreaks.com/topic/27801-users-write-comments-on-a-page/
Share on other sites

I would suggest using a database to accomplish this and also to avoid having to create a page for every video file as well.

With PHP and MySQL you can create a one page to display a user selected video and an add a comment feature.

Here's something to get you started

Form at the end of your page:
[code] <form action="" method="post" name="frmAddComment" id="frmAddComment">
<div align="center">
<table border="0" width="420" cellpadding="0" cellspacing="0">
<tr>
<td><span class="text1">Do you have a comment?&nbsp;&nbsp;

</span></td>
</tr>
<tr>
<td height="1"></td>
</tr>
<tr>
<td><textarea rows="3" name="txtCommentMessage" class="form2"></textarea></td>
</tr>
<tr>
<td height="5"></td>
</tr>
<tr>
<td align="right"><input name="btnAddComment" type="submit" id="btnAddComment" value="Add comment"></td>
</tr>
</table>
</div>
</form>
[/code]
thankyou both for the replys.

speedy33417 ive pasted that script into the page and spend a while studying it. however what do i do next? will i have to set up my database or maybe it doesnt need a database for this.

The forum you gave me is the one i am looking for and when the user writes a comment and presses submit the comment should appear below it and above any other previous comments made.

Any further help or guidance would again be very much appreciated
thank you fert for you reply. i have a mysql database but not sure how to structure it for this. could anyone advise me please on the variables and where they go?

sorry my knowledge in php is not my great area but any help in accomplishing is goal will be great.
[code]
$cn=@mysql_connect("host","username","password") or die(mysql_error());

if($_GET[video]!="")
{
echo "<embed scr=\"videos/".$_GET[video]."\" name=\"{$_GET[name}\">";
echo "<form method=\"post\" action=\"{$_SERVER[PHP_SELF]}\"."?addcomment={$_GET[video]}\">";
echo "<p><textarea name=\"msg\" row=\"10\" cols=\"30\">Comments</textarea></p><p><input type=\"submit\" value=\"comment\"></p>";
echo "</form>";
}

if($_GET[view_comments]!="")
{
$result=@mysql_query("SELECT `comments` FROM `$_GET[view_comments]`",$cn) or die(mysql_error());
$row=mysql_fetch_array($result);

echo "<table>";
echo $row[0];
echo "</table>"
}

if($_GET[addcomment]!="")
{
$result=@mysql_query("SELECT `comments` FROM `$_GET[addcomment]`",$cn) or die(mysql_error());

$row=mysql_fetch_array($result);

$text=$row[0];
$text.="<tr><td>";
$text.=$_POST[msg];
$text.="</tr></td>";
}
@mysql_close($cn);
[/code]
that should do everything you want

your database needs a table for each video with the following syntax:
[code]
TABLE `table_name` (comments TEXT)
[/code]
Sorry.

Your page should start kind of like this:

[code]if (isset($_POST['txtCommentMessage']))
{   
    $message = $_POST['txtCommentMessage'];

//validate message if needed
//then...

$query = "INSERT INTO comments (video_id, user_id, date, comment)
VALUES ('$video_id', '$user_id', '$time', '$message')";
[/code]

My example DOES require a database. In my case there's a registration required as well. In your case you don't need to store a user_id, but might want to store at least a nick name or full name instead.

You need a database with a comments table and 5 fields at least: comment_id, video_id, nick_name, comment.

Oops, you won't need video_id field until you have your videos in the database as well. Which I highly recommend!

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.