From 155ae821fb0036eb1f221b60605c16d301f710be Mon Sep 17 00:00:00 2001 From: "Rajdeep Mehra (mehrar)" Date: Fri, 15 Oct 2021 22:55:48 +0100 Subject: [PATCH] Update and rename studentdeatils inserted into database to insert_db.h --- insert_db.h | 30 +++++++++++++++++++++++++++ studentdeatils inserted into database | 29 -------------------------- 2 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 insert_db.h delete mode 100644 studentdeatils inserted into database diff --git a/insert_db.h b/insert_db.h new file mode 100644 index 0000000..f2c3531 --- /dev/null +++ b/insert_db.h @@ -0,0 +1,30 @@ +#ifndef INSERT_DB_H +#define INSERT_DB_H +#include +#include "select_db.h" +#include "libsqlite.hpp" +using namespace std; + +int insert_db(int studentID, string name, string surname, string username, string email, string password) +{/*insert the student details into database*/ + try{ + sqlite3::sqlite db("School.db"); + auto cur = db.get_statement(); + cur->set_sql( "INSERT INTO Studentdetails VALUES(?,?,?,?,?,?,?);" ); + cur->prepare(); + cur->bind( 1, studentID ); + cur->bind( 2, name ); + cur->bind( 3, surname ); + cur->bind( 4, username ); + cur->bind( 5, email ); + cur->bind( 6, password ); + cur->step(); +} + catch( sqlite::exception e ) + { + cerr << e.what() << endl; + return 1; + } + return 0; +} +#endif diff --git a/studentdeatils inserted into database b/studentdeatils inserted into database deleted file mode 100644 index e98dfca..0000000 --- a/studentdeatils inserted into database +++ /dev/null @@ -1,29 +0,0 @@ -int firstentry(){/*Enter your student details so they are saved in the database*/ -cout << "Student ID"; cin >> studentID; -cout << "Name :"; cin >> name; -cout << "Surname :"; cin >> surname; -username = surname + name[0]; -cout << "Enter your school email :"; cin >> email; -cout << "Password :"; cin >> password; -cout << "Enter Password again :"; cin >> retry; - -if(retry == password){ - sqlite3 *db; - char *column = 0; - int load; - string sql; - - load = sqlite3_open("School.db", &db); - - if(load){ - cout << "DB Error: " << sqlite3_errmsg(db) << endl; - sqlite3_close(db); - return(1); - } - sql = "INSERT INTO STUDENTDETAILS VALUES(" + studentID + ',' + name + ',' + surname + ',' + username + ',' + email + ',' + password + ");"; - - load = sqlite3_exec(db, sql.c_str(), callback, 0, &column); - sqlite3_close(db); - - cout << "Succesfully made your student login."<