Home > front end >  Why can't my Nodejs application cannot see my sqlite3 database column?
Why can't my Nodejs application cannot see my sqlite3 database column?

Time:01-06

There are not errors associated with database or table, but it is not seeing the columns. This is the error: Node server is running.. SQLITE_ERROR: no such column: scene

This is the table:

CREATE TABLE animalStream (
id INTEGER PRIMARY KEY AUTOINCREMENT,
cascade_name TEXT NOT NULL,
enclosre_name TEXT NOT NULL,
scene TEXT NOT NULL,
sensorCamAddress TEXT NOT NULL,
streamerCamAddress TEXT NOT NULL,
duration INTEGER NOT NULL
);

The Nodejs code below allows me to receive data from the HTML form

 const path=require('path');
  const sqlite3 = require("sqlite3").verbose();
  const db_name = path.join(__dirname, "wildlife.db");
  const db = new sqlite3.Database(db_name);

var express = require('express');
var app = express();

var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));

app.get('/', function (req, res) {
    res.sendFile('/home/harry/interface/in9.html');
});

app.post('/submit-student-data', function (req, res) {
  var scene = req.body.scene 
  var cascade_name = req.body.cascade_name;
  var enclosre_name = req.body.enclosre_name;
  var sensorCamAddress = req.body.sensorCamAddress
  var streamerCamAddress = req.body.streamerCamAddress
  var duration = req.body.duration;

db.run(`INSERT INTO animalStream(scene) VALUES(scene)`, ['C'], function(err) {
    if (err) {
      return console.log(err.message);
    }
    // get the last insert id
    console.log(`A row has been inserted with rowid ${this.lastID}`);
  });

});/////////////////

var server = app.listen(3000, function () {
    console.log('Node server is running..');
});

<!DOCTYPE html>

<html><body style="background-color:black;"><blockquote><blockquote>
        <form action="/submit-student-data" method="post">
<p style="color:white;">Cascade file name:<br>
<input type = "text" name = "cascade_name" /></p>

<p style="color:white;">Enclosure name:<br>
<input type = "text" name = "enclosre_name" /></p>

<p style="color:white;">Scene number:<br>
<input type = "text" name = "scene" /></p>

<p style="color:white;">Sensor Camera IP address:
<br> <input type = "text" name = "sensorCamAddress" /></p>
                                                                                                               >
<p style="color:white;">Streamer Camera IP address:
<br> <input type = "text" name = "streamerCamAddress" /></p>

<p style="color:white;">Scene duration:
<br><input type = "text" name = "duration" /></p>
         <br>
        <center> <INPUT type="submit" value="Send">  <INPUT type="reset"></center>
         </form>
</blockquote></blockquote>
</body></html>

As I mentioned, it seems to pick up the database and table fine. It just doesn't see the columns for some reason. I would appreciate any input.

CodePudding user response:

I think you must write your query like this:

`INSERT INTO animalStream (scene) VALUES("${scene}")`

and also you didn't set any value to other column that set NOT NULL

  •  Tags:  
  • Related