I am using c/c++ with sqlite. My code shown below compiles but after I entered my password, I encountered this error.
SQL error: near "NSERT": syntax error
I am unable to identify where exactly the syntax error is.
code
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
#include <string>
#include <iostream>
void insertIntoTable(std::string userName,std::string password);
int main () {
std::string userName;
std::string password;
std::cout << "Enter a user name" << std::endl;
std::cin >> userName;
std::cout << "Enter a password" << std::endl;
std::cin >> password
insertIntoTable(userName,password);
}
//method to insert into table
void insertIntoTable(std::string userName,std::string password) {
sqlite3 *db;
char *zErrMsg = 0;
int rc;
const char *sql;
int i = 1;
int j = 1;
rc = sqlite3_open("test.db", &db);
if( rc )
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
exit(0);
}else
{
fprintf(stderr, "Opened database successfully\n");
}
//query
sql = "INSERT INTO Login (_id,username,password,manager_id) " \
"VALUES ("+i,userName,password,j+");";
}
Please help. thanks
sql = "INSERT INTO Login (_id,username,password,manager_id) " \ "VALUES ("+i,userName,password,j+");";, the comma-operator makes it likesql = "INSERT INTO Login (_id,username,password,manager_id) " \ "VALUES ("+i;/* plus other junk that is effectively ignored (as the expressions are evaluated but discarded) */