Syntax Problem in Query

Hey guys, i am having a problem in my query statement. I am using Mysql in Netbeans and c++.

What i am trying to do is for the user to enter a certain value and then the program will store the value into the database...

string NewMovie ;

Cout <<" Enter your new movie  : " << endl ; 
 cin << NewMovie ;

Basically, the person will enter a new movie(in this case Avatar) and the input will be saved to a string called NewMovie.

Here is when my problem starts...How do i input this variable into an insert sql statement. I check my statement and i tried hardcoding my data like this...

  mysql_query(conn,"INSERT INTO movie_info (movie_title , values ('Avatar')"   );

The database will be updated. But if im using a variable called NewMovie, what can i do for it to be able to be read by the query?

I read up Cstring and ostreamstring but i do not get how they are used. Could sombody show me using the the example i gave above how i can solve my problem.

I am not sure, but I think that is C++? Despite the 'Cout' :wink:

The you can try the C++ way:

#include <sstream>

...

std::stringstream ss;
ss << "INSERT INTO movie_info (movie_title , values ( '";
ss << NewMovie;
ss << "' ) )"; 

std::string query = ss.str ();

Or you do it the C way, using sprintf:

#include <stdio.h>

...

char query[1024]; // make sure thats large enough

snprintf (query, 1023, "INSERT INTO movie_info (movie_title ,  values ( '%s' ) )"
             NewMovie);

I am not very familiar with SQL, so probably made some typos above :wink: