I want to insert into mysql database from C.
Here is my code:
…
for (i=0;i<nb_of_subscribers*hits_subscriber;i++)
{ RandomSub= rand() % nb_of_subscribers + 1;
RandomContent= rand() % (contents_tag*tags) + 1;
mysql_query(conn, "INSERT INTO CONTENT_HITS(CONTENT_ID,SUBSCRIBER_ID) VALUES(RandomContent,RandomSub)");}
…
The problem is :The insert query is not executed and nothing appears in the database.
Thank you.
How do the values for
RandomSubandRandomContent(that you’ve declared) actually get into the query you’re executing? You’re trying to runwhich will fail as it’s trying to put two strings into (I guess) two integer fields.
You need to substitute the values of
RandomContentandRandomSubinto the string:As @SpacedMonkey says – you should be using a prepared statement for this
Pretty basic C stuff to be honest.
PS – do some accepts – 10% isn’t great