Wiki Type editing

Discussion in 'PHP' started by kkonline, Aug 26, 2007.

  1. #1
    I am working on an editing of article manager.

    However whatever changes i do those are reflected on wow but the wow_history table only has the original entry and the previous edits are not stored.

    The wow_history and wow table both have id as auto increment.

    if i write

    Code:
    $add_history = "INSERT INTO wow_history(contributed_by) SELECT (contributed_by) FROM wow WHERE id = $id";
    mysql_query($add_history);


    Then all the changes in contributed by field are logged (all the edits are noted in wow_history)

    So something should be done to id, so i can use something like

    $add_history = "INSERT INTO wow_history SELECT * FROM wow WHERE id = $id";
    mysql_query($add_history);


    
    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'];
        
    $add_history = "INSERT INTO wow_history SELECT * FROM wow WHERE id = $id";
    mysql_query($add_history);
    echo "wow_history updated";
    
        // 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;
        }
    }
    
    Code (markup):
     
    kkonline, Aug 26, 2007 IP