Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Update MySql DB using Classes

$
0
0

Hey all, How would I make it so this code will update the database?

In the class(name is News) I have this function:

public function save($isNewNews = false) {
        $db = new DB();
        if(!$isNewNews) {
            $data = array(
                "Title" => "'$this->Title'",
                "descrip" => "'$this->descrip'",
                "Content" => "'$this->Content'",
                "Image" => "'$this->Image'",
                "colour" => "'$this->Image'",
                "tags" => "'$this->tags'"
            );
            
            $db->update($data, 'news', 'id = '.$this->id);
        }else {
            $data = array(
                "Title" => "'$this->Title'",
                "descrip" => "'$this->descrip'",
                "Content" => "'$this->Content'",
                "colour" => "'$this->colour'",
                "Image" => "'$this->Image'",
                "tags" => "'$this->tags'",
                "date" => "'".date("Y-m-d H:i:s")."'"
                    
                
            );
            
            $this->id = $db->insert($data, 'news');
        }
        return true;
    }
    

To add a new row to the DB i call
$foo = new News($data);
$foo = save(true);


If i try $foo = save(false);

It returns a MySql error


Viewing all articles
Browse latest Browse all 13200

Trending Articles