Location: PHPKode > scripts > ajaxCRUD > ajaxcrud/classes/ajaxCRUD.class.php
<?php
    include_once ('preheader.php');

    header("Cache-Control: no-cache, must-revalidate");
    //A date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    $action = $_REQUEST['action'];

    $table = $_REQUEST['table'];
    $pk = $_REQUEST['pk'];
    $field = trim($_REQUEST['field']);
    $id = $_REQUEST['id'];
    $val = $_REQUEST['val'];

    //default
    if ($action == '') $action = 'update';

    if ($action == 'add'){
        echo $_SESSION['the_table_div'];
    }

    if ($action == 'update'){
        $val = str_replace("<P>","<br /><br />", $val);
        $val = str_replace("<p>","<br /><br />", $val);

        $val = str_replace("</P>","", $val);
        $val = str_replace("</p>","", $val);

        //check to see if  record exists
        $row_current_value = q1("SELECT $pk FROM $table WHERE $pk = \"$id\"");
        if ($row_current_value  == ''){
            qr("INSERT INTO $table ($pk) VALUES (\"$id\")");
        }

        $success = qr("UPDATE $table SET $field = \"$val\" WHERE $pk = \"$id\"");

        if ($val == '') $val = "&nbsp;&nbsp;";

        $prefield = $id . $table . $field;

        if (isset($_REQUEST['dropdown_table'])){
            $dropdown_table     = $_REQUEST['dropdown_table'];
            if ($dropdown_table != ''){
                $val = "{selectbox}";
            }
        }

        if ($success){
            echo $prefield . "|" . stripslashes($val);
        }
        else{
            echo "error|" . $prefield . "|" . stripslashes($val);
        }
    }

    if ($action == 'delete'){
        $success = qr("DELETE FROM $table WHERE $pk = \"$id\"");

        if ($success){
            echo $id;
        }
        else{
            echo "error|" . $id;
        }
    }

?>
Return current item: ajaxCRUD