SQLite Forum

Select Query will not work in PHP program
Login
How d'ye expect your insertRecord method to know what $db is? You need to pass that through to that method as a parameter:

insertRecord ($db, $query);                        // call to function to INSERT query to database


function insertRecord ($db, $sql)
     {
     echo $sql; // for testing purposes only
     $ret = $db->exec($sql);
     if(!$ret)
          {
          echo $db->lastErrorMsg();
          }
     else
          {
          echo "Records created successfully\n";
          }
     }

and why are you closing the database in your insertRecord method?

etc.