Example #1
0
    public function create($title, $content, $image, $idAuthor)
    {
        $article = new Article($this->db);
        try {
            $article->setTitle($title);
            $article->setContent($content);
            $article->setImage($image);
            $article->setIdAuthor($idAuthor);
        } catch (Exception $e) {
            $errors = $e->getMessage();
            echo $errors;
        }
        if (!isset($err)) {
            $title = $this->db->quote($article->getTitle());
            $content = $this->db->quote($article->getContent());
            $idAuthor = $article->getIdAuthor();
            if ($image == "") {
                $query = 'INSERT INTO article(title, content, idAuthor)
						VALUE (' . $title . ',' . $content . ',' . $idAuthor . ')';
            } else {
                $image = $this->db->quote($article->getImage());
                $query = 'INSERT INTO article(title, content, image, idAuthor)
						VALUE (' . $title . ',' . $content . ',' . $image . ',' . $idAuthor . ')';
            }
        }
        $res = $this->db->exec($query);
        if ($res) {
            $id = $this->db->lastInsertId();
            if ($id) {
                return $this->findById($id);
            } else {
                throw new Exception('Database error');
            }
        } else {
            throw new Exception($errors);
        }
    }
Example #2
0
<?php

require '../class/class_article.php';
if (isset($_POST) && !empty($_POST)) {
    $article = new Article();
    $article->setTitle($_POST['title']);
    $article->setContent($_POST["content"]);
    $article->setIdAuthor($_POST["idAuthor"]);
    $article->setIdDisaster($_POST["idDisaster"]);
    $disaster->setDateCreation(date("Y-m-d H:i:s"));
    $article->create();
    var_dump($article);
    exit;
}