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
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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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