string NewMovie = "ww";      
          string queryText ;

          queryText = "INSERT INTO movie_info (movie_title ) VALUES('" + NewMovie + "')" ;


MYSQL *conn;

conn=mysql_init(NULL);

mysql_real_connect(conn,host,username,password,database,0,NULL,0);

mysql_query(conn,queryText.c_str());

mysql_close(conn);

return 0;

What i would like to know is how am i able to do a check to see if such a movie title already exist?

Perform a select query to look up the movie. If a record is returned, it already exists. Once you know if the record exists, or not, you can then either report an error condition or perform the insert.

yeah, i did try to use SELECT but the problem i faced is how the error statement would look like.

For example

string NewTitle = "ww";
          string queryText ;

 queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'";


  mysql_query(conn,queryText.c_str())

if ??

that is the part im not sure of. Does the statement return a value of 1 or 0 when it is executed and smting is found?

Check your library's documentation for specific information. It should return some sort of success/fail value.

DISCLAIMER: The information contained below is based on my experience with the mysql library in PHP, YMMV.

In PHP, there are a couple exceptions, but in general mysql_query() returns FALSE on an error and TRUE on a success. With the success value alone, you can not determine if you have an empty result set or not. Even an empty result set is still technically a success. Since it's a library, I suspect it will be the same in C++.

You will have to carry your algorithm through to the next step, which is extracting the rows. If when you try to extract a row, you get an empty result (a FALSE return), you release the query and begin your insert routine. If you successfully extract a row, you return an error to the user and abort the insert.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.