dominic600 Posted August 11, 2011 Share Posted August 11, 2011 Does any one know where a good tutorial is on commenting systems. I cant seem to find a good tutorial for what i want to do. Like i want people to be able to comment on each individual post i make on my blog or i may just make a new single page for people to comment but only people that have register on the web site. Thank you, Dominic Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/ Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 That's a pretty specific tutorial. Do you know how to query a database? Why not start from there? You just need to break the problem down into a process of steps and work on each step. This is how programmers write code. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255667 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 yeah, i have my database all set up and stuff. Like i have all my login, register, activate, and all that stuff working properly. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255669 Share on other sites More sharing options...
jcbones Posted August 11, 2011 Share Posted August 11, 2011 Any of the first 4 links will help you. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255670 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 looking at tutorials, I can do it but how would I go about connecting it to my database? like they all say i need to make a new table... And I would like to make it to where they have to be logged into the site inorder to leave a comment. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255673 Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 And I would like to make it to where they have to be logged into the site inorder to leave a comment. Well, you just said you have your login 'all in place'. Do you understand how it works? Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255674 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 yeah I mostly understand, or at least I think I do. or like if I follow a tutorial on making a comments page, is there a way I can impliment my login script into it so you must be logged in to post? Sorry if im not making sense when I ask questions. I'm fairly new and really dont know what all everything does, as you could probably tell from all my threads. lol. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255675 Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 is there a way I can impliment my login script into it so you must be logged in to post? Of course, if you understand how both systems work. What I'm trying to get at is how to think like a programmer instead of spoon feeding yourself through tutorials. Allot of people doing tutorials are in a rush to get things working so they tend to skim past the explinations of why they are typing the crap they are typing. Even if people do pay attention and read this stuff allot of tutorials may not be particularly well written and not explain allot of stuff anyway. Do yourself a favor and try to break the task down yourself. Once you have the task broken down, you simply need to go through each step and create the code. SOme steps may need to be broken down even further along the way. As an example, your comment system. What does it need to do? [pre] 1) If a user is logged in, display a button at the bottom of the each blog post. 2) Once button is clicked, open a text area for the user to post there comment in. 3) Submit the form to the database and add a new record. [/pre] Obviously, this isnt enough information to start coding (for some, it would be as the missing pieces are pretty clear already). So, let's go through the list again and ask ourselves some questions and/or jot down idea.. [pre] 1) If a user is logged in, display a button at the bottom of the each blog post. *) How exactly do we check a user is logged in? *) We can check the $_SESSION array for the flag we added to it when we logged a user in. 2) Once button is clicked, open a text area for the user to post there comment in. *) We can likely take the user to a new page to do this. *) Or, get a little bit fancy and implement it using JavaScript to slide open an already existing text area. 3) Submit the form to the database and add a new record. *) How can we relate this comment to the article? *) Each article has an id in the database. When we create the article (and the optional comment button) we can place this id in a hidden form element. This way it will get sent along with the comment. 4) Database structure: *) Now that we know we will be relating comments to an article via the articles id we can design a simple database. *) What fields to store? *) A comment id, and article id and maybe the users id so we can put there name on the comment. *) How do I get the users id? *) It should likely be in that $_SESSION array I am already using to see if the user is logged in. [/pre] Now we are getting much closer to something that can actually be turned into code. From here, you might go through it again and add in a few more ideas / thoughts. You might need to go and add some stuff to your login system to account for the data your going to need. With this kind of plan in place you don't really need any specific tutorials. If you get stuck, you can come to a forum and say "Hey, Iv'e got this login script, how do I add a user id to the $_SESSION array?" Better still, if you've gone through a similar process to create your login script, you likely won't need to ask those types of simple questions because you will understand completely how this system works, why and how it does what it does. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255683 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 wow, thanks thats alot of helpfull info. Im going to give this a try. Ill let you know how it works out. But thanks again for all the info! Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255685 Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 I'm not usually trying to be nasty when I say things like "go break your problem down into smaller pieces and come back when you have a more specific problem", I'm trying to get people to think for themselves. Most things aren't as difficult as they seem once they are broken down into smaller pieces. The company I work for is in the process of putting in a tender for a Government contracted application. We got a 'functional requirement outline' on Monday which is basically the same sort of thing. Ours (unfortunately) however for this particular project is 257 A4 pages long. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255691 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 yeah i get what your saying, i like being able to figure stuff out for my self lol but yeah i got the commenting part to where it displays the messages and everything now i have to figure out how to make it to where you have to be loged in to access it lol Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255716 Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 Awesome. It's good to see your making progress. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255742 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 okay so i got all this, just by looking at my other php files and i figured this is what it should look like to require the loggin to access it. But it does not work. Do you see what im missing or doing wrong? <?php require("top.php"); ?> <div id='comments'> <?php $getid = $_GET['id']; if(!$getid) $getid = "1"; require("scripts/connect.php"); $query = mysql_query("SELECT * FROM users WHERE id='$getid'"); $numrows = mysql_num_rows($query); if($numrows == 1){ require ("scripts/comment_connect.php"); $getdata = mysql_query ("SELECT * FROM comments ORDER BY date AND time ASC"); while($row = mysql_fetch_assoc($getdata)){ $id = $row['id']; $name = $row['name']; $message = $row['message']; $date = $row['date']; $time = $row['time']; $message = nl2br($message); echo" <table> <tr> <td><b>$name on $date at $time</b></td> </tr> <tr> <td>$message</td> </tr> </table> <br /> <hr />"; } $button = $_POST['button']; if($button){ $name = $_POST['name']; $message = $_POST['message']; if ($name && $message){ $dayofweek = date("l"); $month = date("F"); $dayofmonth = date("d"); $year = date("Y"); $date = "$dayofweek $month $dayofmonth, $year"; $hours = date("g"); $min = date("i"); $sec = date("s"); $amorpm = date("a"); $timezone = date("T"); $time = "$hours:$min:$sec $amorpm $timezone"; require ("scripts/comment_connect.php"); $queryget = mysql_query("SELECT * FROM comments WHERE name='$name' AND message='$message'"); $numrows = mysql_num_rows($queryget); if($numrows != 1){ $query = mysql_query("INSERT INTO comments VALUES ('', '$name', '$message', '$date', '$time')"); echo "Your message has been sent!"; } else echo "You can NOT resubmit the same message!"; } else echo "You did not fill in all fields."; } echo " <form action='comments.php' method='POST'> <table width='400'> <tr> <td width='100'>Name:</td> <td><input type='text' name='name'></td> </tr> <tr> <td width='100'>Message:</td> <td><textarea name='message' cols='50' rows='3'></textarea></td> </tr> <tr> <td width='100'></td> <td><input type='submit' name='button' value='Submit'</td> </tr> </table></form> "; } else echo "This needs to be changed"; ?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1255987 Share on other sites More sharing options...
shlumph Posted August 11, 2011 Share Posted August 11, 2011 When the user logs in, do you give them a session cookie? Do you store anything in $_SESSION to identify them? Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1256025 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 yes, like i have this. $_SESSION['username'] = $dbuser; $_SESSION['userid'] = $dbid; Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1256029 Share on other sites More sharing options...
shlumph Posted August 11, 2011 Share Posted August 11, 2011 You can check if that variable is set before inserting the comment into the DB: session_start(); //Make sure you do this at the very top of your script //Later on in the script if(!isset($_SESSION['username'])) { echo "You must login before commenting"; } else { //Comment script or whatever you want protected. } Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1256091 Share on other sites More sharing options...
dominic600 Posted August 11, 2011 Author Share Posted August 11, 2011 thank you, but sorry if this is a dumb question but where it says !isset what do i put there or does it just stay isset Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1256104 Share on other sites More sharing options...
trq Posted August 11, 2011 Share Posted August 11, 2011 It stays isset(). You are checking to see if the $_SESSION['username'] index exists. This will only exist if the user is logged in. Quote Link to comment https://forums.phpfreaks.com/topic/244467-php-commenting-system/#findComment-1256138 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.