ngreenwood6 Posted September 2, 2008 Share Posted September 2, 2008 Hello all, I have created a section on my site where users can post comments. I as the admin would like to be able to edit these comments or delete them if necessary. I am trying to figure out how to edit or delete them by which one I choose. My page looks something like this: <?php $host = "localhost"; $db = "test"; $user = "user"; $pass = "pass"; mysql_connect($host, $user, $pass); mysql_select_db($db); $query = "SELECT comment from table_name"; while ($row = mysql_fetch_array($query)) { echo "$row <br>"; } ?> This pretty much prints the comments to the page with a break after each comment. I want to have a simple little button like this to edit the comment or delete it: <a href="edit.php">edit</a> The problem I have is that I do not know how to edit that specific comment. The reason is because it is not always going to be the same comment. I would like to be able to pull it into something like this where $comment is the users comment so that I can see what is there and just edit it: <textarea value="$comment"> </textarea> Any help is appreciated. If you have any questions feel free to ask. Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/ Share on other sites More sharing options...
Ken2k7 Posted September 2, 2008 Share Posted September 2, 2008 Well when you generate each comment, add in a link that includes the comment's ID in the table. I'm guessing the table has an ID column right? Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/#findComment-632052 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 Yes, the comments have an id in the table. Im not sure that I know how to do what you are saying. Can you give me an example? I am completely lost when it comes to this any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/#findComment-632401 Share on other sites More sharing options...
Porl123 Posted September 3, 2008 Share Posted September 3, 2008 When you want to edit a specific comment you could add a <input type="id" value="$row[id]" /> in the form on each of the comments, then at the topic in your php, edit it like UPDATE table SET `comment` = '$_POST[new_comment]' WHERE id = '$_POST[id]' Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/#findComment-632406 Share on other sites More sharing options...
Porl123 Posted September 3, 2008 Share Posted September 3, 2008 Woops, sorry <input type="hidden" value="$row[id]" />** been a long day.. Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/#findComment-632407 Share on other sites More sharing options...
ngreenwood6 Posted September 3, 2008 Author Share Posted September 3, 2008 Thanks for the help, but i still have a question. If I don't know what the id of the post is how do this work? Do i just use "id"? Link to comment https://forums.phpfreaks.com/topic/122402-changing-data/#findComment-632604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.