QT SQL DATABASE LOGIN
-
This part:```
else
{QSqlQuery qry; qry.prepare("INSERT INTO payments (SURNAME,LASTNAME,GRADE,CLASS,AMOUNT,DATE)" "VALUES(:SURNAME, :LASTNAME, :GRADE, :CLASS, :AMOUNT, :DATE)"); qry.bindValue(":SURNAME",name); qry.bindValue(":GRADE",grade); qry.bindValue(":CLASS",clas); qry.bindValue(":AMOUNT",amount); qry.bindValue(":LASTNAME",receiver); qry.bindValue(":DATE",date); if(qry.exec()) { QMessageBox::information(this,"inserted","PAYMENTS RECORDED SUCCESSFULLY!"); } else
{
QMessageBox::warning(this,"warning","PAYMENT NOT RECORDED!");
}
}
}
}
} -
Hi,
That's the kind of constraints that should be done at the database level.
Your database structure might also be too simple in the sense that if can be pretty easy to get duplicated data with small typos. -
@GREYON
You should say what goes wrong? Do you get a compilation error? A runtime error? A message? If so, tell us what the message is. Something doesn't do what you expect? If so what, and how do you know? That's what's required for people to look at your issue!qry.prepare("INSERT INTO payments (SURNAME,LASTNAME,GRADE,CLASS,AMOUNT,DATE)" "VALUES(:SURNAME, :LASTNAME, :GRADE, :CLASS, :AMOUNT, :DATE)");
Those two strings get joined. Look at them, and you will realize that will generate in the middle:
... CLASS,AMOUNT,DATE)VALUES(:SURNAME,
The
VALUES
touches the parenthesis to its left, which is different from the sample code at https://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-values. I don't know if that will be enough to error.In any case, when a query goes wrong (if that's what's happening), use https://doc.qt.io/qt-5/qsqlquery.html#lastError to print out the text of the error.
-
@GREYON said in QT SQL DATABASE LOGIN:
@SGaist
Now what are you suggesting items of help?What experience do you have with relational database design ?
-
Well, in that case you should start by learning a bit more about them before going further. At least take the time to go through Qt's SQL module documentation and examples.
-
@GREYON Then please mark this topic as solved, thx.
-
@Christian-Ehrlicher
Okay , thanks for the information,but am new here,how can it mark as solved please?