Home > Mobile >  near "',user'":syntax error Unable to execute statement
near "',user'":syntax error Unable to execute statement

Time:09-15

I am having a mare of a time with a test program I am trying to create in QT.

I am using SQLTE database for employee info and trying to get my user management section to update and save new users on click button.

I am using the following code on push button click but I get the following error; near "',user'":syntax error Unable to execute statement and for the life of me I cannot work out why..

Can someone help.

void oviewsettings::on_pushButton_clicked()
{
QString Name, Surname, Access, Phone, Email, Username, Password;
Name=ui->lineEdit_usermanagement_Name->text();
Surname=ui->lineEdit_usermanagement_Surname->text();
Access=ui->lineEdit_usermanagement_Access->text();
Phone=ui->lineEdit_usermanagement_Phone->text();
Email=ui->lineEdit_usermanagement_Email->text();
Username=ui->lineEdit_usermanagement_Username->text();
Password=ui->lineEdit_usermanagement_Password->text();



OViewMain conn;
if(!conn.connOpen()){
    qDebug()<<"Failed to open the database";
    return;
}
conn.connOpen();
QSqlQuery qry;
qry.prepare("insert into employeeinfo ([Name],[Surname],[Access],[Phone],[Email],[Username],[Password]) values ('" Name "'," Surname "'," Access "','" Phone "','" Email "','" Username "','" Password "')");

if(qry.exec("insert into employeeinfo ([Name],[Surname],[Access],[Phone],[Email],[Username],[Password]) values ('" Name "'," Surname "'," Access "','" Phone "','" Email "','" Username "','" Password "')"))
{
    QMessageBox::critical(this,tr("Save"),tr("Database Updated, Saved"));
    conn.connClose();
}
else
{
    QMessageBox::critical(this,tr("Error"),qry.lastError().text());
}

CodePudding user response:

You are missing apostrophe before " Surname "' and " Access "'. Plus there are more strange things in your code, but they probably do not cause the error. For example why do you call connOpen() twice or why do you repeat the query code in prepare() and in exec()? And if you are serious about error handling, you should also check return value from prepare().

  • Related