I don't know what I'm doing wrong, but I get undefined variables in my query, while the variables are set. I'm trying to create a table and then put some data into it
const obj = {
time: new Date(),
taken: 0,
given: 6.4
}
const pool = mariadb.createPool({
host: 'localhost',
user: 'root',
password: 'root',
database: 'P1data'
})
pool.getConnection().then(async conn => {
let createLive = `create table if not exists live(
time datetime primary key,
taken float not null,
given float not null
)`
conn.query(createLive, (err) => {
if(err) console.error(err.message)
})
const res = await conn.query(`SHOW TABLES`)
console.log(res)
conn.end(err => {
if(err) console.error(err.message)
})
}).catch(err => {
if(err) console.error(err)
})
pool.getConnection().then(conn => {
conn.query(`INSERT INTO live(time, taken, given) VALUES (${obj.time}, ${obj.taken}, ${obj.given});`)
.then(rows => {
console.log(rows);
conn.end();
})
.catch(err => {
console.error(err)
})
}).catch(err => {
if(err) console.error(err)
})
The error I get looks like this:
Error: (conn=354, no: 1054, SQLState: 42S22) Unknown column 'undefined' in 'field list' sql: INSERT INTO live(time, taken, given) VALUES (undefined, 0, undefined); - parameters:[]