Friday 19 October 2018

Having some problems writing to a database

So I've sort of got through my first problem (getting a column error), but am now getting null in all fields of my database when the write happens. Here's a chunk of what I've got (I left out some of the variable declarations, they're all similar to what you see here)var gameSession = gameDetails[5] var gameType = gameDetails[6] var otherInfo = mySQL.escape(gameDetails[7]) || "No info" var sql = 'INSERT INTO gameinfo VALUES (`GameName`, `system`, `days`, `timeRange`, `gameSession`, `gameType`, `otherInfo`);' connection.query(sql, function(err, result){ if(err) throw err; console.log("1 record inserted"); }); Now, I've never played with databases before, but in trying to get this to work and reading documentation, it seems like this insert is supposed to take the variables, and make that that variables position, the contents of that variable. However, if I change one of the names of my variables, say 'GameName' to just 'Name' in the code, but not the DB i get an errorError: ER_BAD_FIELD_ERROR: Unknown column 'Name' in 'field list' Which looks to me like either 1) I'm supposed to have my database columns with the same name as my variables (which I thought was a bad practice, as it made attacks easier) or 2) I'm completely misunderstanding, something.

Submitted October 19, 2018 at 11:38AM by akuthia

No comments:

Post a Comment