Jump to content

Recommended Posts

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

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.

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.

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.

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.