ngreenwood6 Posted September 3, 2008 Share Posted September 3, 2008 Hello, I am looking for a page where a user can submit comments. I want the comments to be editable and deletable if I am logged in as admin. Can someone give show me an example of how you would accomplish this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/ Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 You'll need just some basic PHP and MySQL knowledge which you can get in a snap. No one can give you full working code, you'll have to accomplish this yourself. For some resources, take a look at the manual and this page. Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-632785 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 Well I have the comments page and the database already set up. I can post the comments to a page and have them show up on another. The problem I have is trying to figure out how to edit or delete the comments. I have them in the database and can pull them onto the page. What I don't understand is how to select a certain comment and have it edit that specific one. Can you help me with this. An example is what I am looking for because I am a noob and am trying to learn. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-632793 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-632841 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 seriously no one has any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-632926 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 No one has any suggestion probably of the fact that you're asking for too much. I said you, we are here to help on bits of code or logic, not write full code for you. I highly suggest to start reading about php, mysql and their interaction before starting on a real project. What I don't understand is how to select a certain comment and have it edit that specific one On the admin page (if you have one), each comment's title in the db table is shown with a link to a an edit page. The link passes an url variable (aka GET) like this: "edit.php?id=7" which will determine the comment you have selected. In the edit.php page, the variables is accessed via the $_GET superglobal and a query is run to fetch the content (author, date, etc) of that comment. Those data are shown in a form, that when submitted triggers a small script (in the same page) that uses the UPDATE mysql keyword to edit the comment with the information got from the form data (accessed via POST). Investigate on that and if you still fail, I (or someone else) will post some code to give you the idea. But I doubt that you'll need that help if you study just a bit. Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-633000 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 Im sorry but I just don't get it. I have a page like this: <?php $host = "localhost"; $user = "user"; $pass = "pass"; $db = "db"; $connect = mysql_connect($host, $user, $pass); $select_db = mysql_select_db($db); $query = "SELECT * from table"; while($row = mysql_fetch_array($query)) { echo "$row<br><a href='edit.php'>edit</a><br>"; } ?> The problem is that it returns however many comments are in the database(i will not know how many there are). I do not have anything on the edit.php page yet because I do not know how to edit that specific comment because there will be 5 different ones if there are 5 in the database. Can someone please explain to me how I would accomplish what I am trying to accomplish? An example would work best. I just did this to show that I do have knowledge of php and mysql for those doubting. Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-633010 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 Hmm ok, did you investigate on the subjects i suggested? A very simple example could be: comments show page (admin) <?php $results = mysql_query("SELECT * FROM table"); //make the query while($values = mysql_fetch_array($results)){ //loop through the rows echo '<a href="edit.php?id=' . $values['id'] . '">' . $values['comment_title'] . '</a>'; //print the link to the edit.php page } ?> comments edit page (admin) <?php if(isset($_GET['id'])){ //check if the GET variable is set, so the edit page will be shown $id = mysql_real_escape_string($_GET['id']); //clean the variable if(isset($_POST['submit'])){ //check if the form is submitted, so the update query can be run $comment = mysql_real_escape_string(htmlentities($_POST['comment'])); //clean the input text $resultsUpdate = mysql_query("UPDATE table SET comment_text='$comment' WHERE id=$id"); //make the update query } $results = mysql_query("SELECT * FROM table WHERE id=$id"); //make the select query to show the comment in the textarea $values = mysql_fetch_array($results); //fetch the returned row. Don't need a while loop as the query will return only one row ?> <form id="form" method="post" action=""> <textarea id="comment" name="comment"><?php echo $values['comment_text']; ?></textarea> <input type="submit" id="submit" name="submit" value="Save" /> </form> <?php } else{ //this will show when the GET variable isn't set echo 'How did you find this page?'; } ?> If you don't understand it this time, i'll give up. Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-633156 Share on other sites More sharing options...
ngreenwood6 Posted September 4, 2008 Author Share Posted September 4, 2008 I have got it now and it works perfectly. I have modified it for my needs. Thank you for your help that was great. Quote Link to comment https://forums.phpfreaks.com/topic/122560-solved-creating-comments-page/#findComment-633638 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.