3
Contributors
2
Replies
24
Views
3 Years
Discussion Span
Last Post by gabrielcastillo
0

What have you tried so far? Plus we would need database structure, information about what needs to be inserted, deleted and edited...

1

Here is a simple class that uses mysql to get you started. This was just showing you an example.. you would need to sanitize the data and do some validation checking.

class Crud {

    public function edit($data = array(), $row_id)
    {
        $query = mysql_query("UPDATE `table_name` SET field_name='{$data['value']}', field_name='{$data['value']}', field_name='{$data['value']}' WHERE id='$row_id'");
        if(!query) die("Failed to update query").mysql();

        $query = mysql_affected_rows();

        if($query == 1){
            return true;
        }else{
            return false;
        }
    }


    public function insert()
    {
        $query = mysql_query("INSERT INTO `table_name` (`field_name`, `field_name`) VALUES('{$data['value']}','{$data['value']}')");

        $query = mysql_affected_rows();

        if($query == 1){
            return true;
        }else{
            return false;
        }

    }

}


$crud = new crud();

$edit = $crud->edit(array('field_name' => 'value', 'field_name' => 'value', 'field_name' => 'value'), 100);

if($edit == true){
    echo 'successful edit';
}else{
    echo 'Failed edit';
}

Edited by gabrielcastillo: changed the code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.