Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:50:37+00:00 2026-06-05T04:50:37+00:00

I am using this code for inserting data , but insert data in hard

  • 0

I am using this code for inserting data , but insert data in hard code, but my need is to insert data from user side using c++ , can any one insist me:**

#include <iostream>
 using namespace std;
#include "sqlite3.h"
 int main (int argc, const char * argv[]) {

sqlite3 *db;
sqlite3_open("test1.db", & db);


string createQuery = "CREATE TABLE IF NOT EXISTS items (userid INTEGER PRIMARY KEY, ipaddr TEXT,username TEXT,useradd TEXT,userphone INTEGER,age INTEGER, "
                                                "time TEXT NOT NULL DEFAULT (NOW()));";
  sqlite3_stmt *createStmt;
  cout << "Creating Table Statement" << endl;
  sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
  cout << "Stepping Table Statement" << endl;
  if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;

  string insertQuery = "INSERT INTO items (time, ipaddr,username,useradd,userphone,age) VALUES ('', '192.167.37.1','rahul da','benerghatta','9966524824',24);"; // WORKS!
  sqlite3_stmt *insertStmt;`enter code here`
  cout << "Creating Insert Statement" << endl;
  sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
  cout << "Stepping Insert Statement" << endl;
  if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;

  string selectQuery = "select * from items where ipaddr='192.167.37.1' & username= 'rahul';";
  sqlite3_stmt *selectStmt;
     cout << "Creating select Statement" << endl;
     sqlite3_prepare(db, selectQuery.c_str(), selectQuery.size(), &selectStmt, NULL);
     cout << "Stepping select Statement" << endl;
     if (sqlite3_step(selectStmt) != SQLITE_DONE) cout << "Didn't Select Item!" << endl;

     cout << "Success!" << endl;

   return 0;
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:50:39+00:00Added an answer on June 5, 2026 at 4:50 am

    It really depends on what from the data you’ve got is stored in. If you’ve got it in specific variables then you could use std::stringsteam to acheive what you want to do:

    std::stringstream insertQuery;
    insertQuery << "INSERT INTO items (time, ipaddr,username,useradd,userphone,age)"
                   " VALUES ('" << time
                << "', '" << ipaddr
                << "', '" << username
                << "', '" << useradd
                << "', '" << userphone
                << "', " << age << ")";
    sqlite3_prepare(db, insertQuery.str().c_str(), insertQuery.size(), &insertStmt, NULL);
    

    Note the additional call .str() on the stringstream to return a string.

    Of course, you’ll have to ensure that your data is valid for the type of columns you’re inserting it into. This is especially true if your input is coming straight from users – watch out for common gotchas such as embedded quotes and meta characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm inserting data from a jsf page to database using managed beans. But the
Using This code: I am tring to fill the page with the data and
Im using this code: protected String getContactInfo() { Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null,
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I'm loading and inserting html-code using Jquery Load() method. But when I'm trying to
I'm trying to insert registration data into a database but my php code isn't
I've had a look around but can't seem to find any information on this.
i am trying to insert data to database but it removing braces'{}' while inserting
Using this code I am inserting the code into listbox. <select id=lstCodelist size=17 name=lstCodelist
Using this code, i am able to send a notification to my own device.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.