SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Wiki Type editing

    I am working on an article manager. The table has 2 field by name of modified and trusted.

    modified trusted meaning
    0 0 Submission of form (by user) having content
    1 0 User has performed some editing
    0 1 By Admin. Contents having this configurations are only displayed on the website


    Everything is working fine. However I have one issue in mind.

    Whenever a user edits the content then modified=1 and trusted=0 and that content will not be displayed. Now the modified content is available in the database. But i loose the original content as i am using UPDATE command in mysql ! So is there any solution (simple one) so that i donot loose the original content and also get the modifications

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, there is.

    Don't use the UPDATE statement, but INSERT the data, making sure you have a timestamp field. Then, the script which calls the data will need this at the end of the MySQL query:
    Code:
    ORDER BY `Timestamp` DESC
    .
    That will look for the latest record of that data.

    This means that all of the data is where it always has been.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Quote Originally Posted by arkinstall View Post
    Yes, there is.

    Don't use the UPDATE statement, but INSERT the data, making sure you have a timestamp field. Then, the script which calls the data will need this at the end of the MySQL query:
    Code:
    ORDER BY `Timestamp` DESC
    .
    That will look for the latest record of that data.

    This means that all of the data is where it always has been.
    The below is the extract of article editing which i am using. Rather than having timestamp in database i use
    Code:
    $date=strtotime("now")
    and then send $date in db. Is that ok?

    please guide me how to make the changes using INSERT

    PHP Code:
    if (isset($_POST['content'])) {
    // data has been sent

        // get data and make it safe for query
        
    $id mysql_real_escape_string($_POST['id']);
        
    $name mysql_real_escape_string($_POST['name']);
        
    $title mysql_real_escape_string($_POST['title']);
        
    $content mysql_real_escape_string($_POST['content']);
        
    $mood mysql_real_escape_string($_POST['mood']);
        
    $tags mysql_real_escape_string($_POST['tags']);
        
    $date strtotime("now");
        
    $ip $_SERVER['REMOTE_ADDR'];

        
    // query to edit opening
        
    $edit "UPDATE wow SET
        contributed_by = '
    $name',
        content = '
    $content',
        title = '
    $title',
        mood = '
    $mood',
        tags = '
    $tags',
        date = '
    $date',
        ip = '
    $ip',
        trusted='0',
        modified='1'    
        WHERE id = 
    $id";
        
    $result mysql_query($edit) or die (mysql_error());
        
        
    // did it work?
        
    if ($result) {
            echo 
    ' Thank you.<br /><br />';
        } else {
            echo 
    'Error! The values sent are below.<br /><br />';
            echo 
    $content;
        }
    }

     if (isset(
    $_GET['id'])) {

        
    $edit "SELECT * FROM wow WHERE id = {$_GET['id']}";

        
    $result mysql_query($edit) or die (mysql_error());

        
    $row mysql_fetch_array($result);
        
    ?> 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •