Uncaught Error: Call to a member function bindParam() on boolean [duplicate]

  pdo, php

error
form
I am stucking on this error for hours ,and i still didn’t figure out. I am trying to to get this lab soon. Your helps would be appreciated. Thank you guys.

//controllers/chirp.php
function post_add() {
   $chirp_content = safeParam($_POST, 'chirp_content', '');
    $author = safeParam($_POST, 'author', '');
    insert($chirp_content,$author);
    redirectRelative("index");
}

//Models/chirp.php
function insert($chirp_content,$author) {
  global $db;
  $st = $db -> prepare("INSERT INTO chirps (chirp_content, author, datestamp) values (?, ?, DATE())");
  $st -> bindParam('chirp_content', $chirp_content);
  $st -> bindParam('author', $author);
  $st -> execute();
  return $db->lastInsertId();
 }
//db.php
<?php
global $db;
try {
    $db = new PDO('sqlite:chirper.db3');
    if (!$db) {
      print_r($db->errorInfo());
    }
} catch (PDOException $e) {
    die("Could not open database. " . $e->getMessage() . $e->getTraceAsString());
}

function adHocQuery($q) {
    global $db;
    $st = $db -> prepare($q);
    $st -> execute();
    return $st -> fetchAll(PDO::FETCH_ASSOC);
}
?>

/*
//chirp.sql
CREATE TABLE `chirps`
(
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  datestamp DATETIME NOT NULL,
  chirp_content VARCHAR(140) NOT NULL,
  author VARCHAR(25) NOT NULL
); */
<!--view/chirp.php-->
<form action="@@chirp/[email protected]@" method="post">
      <div class="form-group">
        <label for="chirp_content">Chirp Content</label>
        <textarea class="form-control" id="chirp_content" name="chirp_content" placeholder="Enter content" rows="12" maxlength="140" value=""></textarea>
      </div>
      <div class="form-group">
        <label for="tags">Author Name</label>
        <input type="text" min="1" max="25" id="author" name="author" class="form-control" placeholder="Enter author name" value=""/>
      </div>
      <div class="form-group">
        <div class="btn-toolbar align-middle">
          <button type="submit" class="btn btn-primary mr-1 d-flex justify-content-center align-content-between"><span class="material-icons">send</span>&nbsp;Send Chirp</button>
          <button class="btn btn-secondary mr-1 d-flex justify-content-center align-content-between" onclick="get('/index')"><span class="material-icons">cancel</span>&nbsp;Cancel</button>
        </div>
      </div>
      <input type="hidden" id="datestamp" name="datestamp" value="" />
    </form>

Source: Ask PHP

LEAVE A COMMENT