blackandwhite Posted November 19, 2006 Share Posted November 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
fert Posted November 19, 2006 Share Posted November 19, 2006 i would recommend using $_GET for the video name and have a table in for each of the videos that would hold the comments. Quote Link to comment Share on other sites More sharing options...
speedy33417 Posted November 19, 2006 Share Posted November 19, 2006 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 startedForm 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? </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] Quote Link to comment Share on other sites More sharing options...
blackandwhite Posted November 19, 2006 Author Share Posted November 19, 2006 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 Quote Link to comment Share on other sites More sharing options...
fert Posted November 19, 2006 Share Posted November 19, 2006 this will need a database unless you want to have lots of files on your server. Quote Link to comment Share on other sites More sharing options...
blackandwhite Posted November 19, 2006 Author Share Posted November 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
fert Posted November 19, 2006 Share Posted November 19, 2006 [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 wantyour database needs a table for each video with the following syntax:[code]TABLE `table_name` (comments TEXT)[/code] Quote Link to comment Share on other sites More sharing options...
speedy33417 Posted November 19, 2006 Share Posted November 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.