phpredbean

Number in database is not updated using RedBeanPHP


Using RedBaeanPHP, I want the page to be updated and add + 1 to the "view". Please help me, I don't understand it very well.

$post_id = $_GET['post_id'];
$posts = R::load('posts', $post_id);

if (isset($_SESSION['recent_posts'])) {
    R::exec('UPDATE posts SET view = "view" + 1 WHERE id = $posts["id"]');
};

When a page is refreshed, it is not added to the database.


Solution

  • Thanks, already solved the problem

    $id = $posts['id'];
    $view = "UPDATE `posts` SET `view` = `view` + 1 WHERE `id`= $id";
    R::exec($view);