if we have to insert records into a mysql database using c api then the general code is this

if (mysql_query(conn, "insert into empinfo values ('saikat banerjee')")) 
  {
      printf("4Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

but, here we have to enter the record from the code itself .

but, i want to enter records from direct user inputs.
like, save the user input in a say, string variable and then use that string variable to store the record in the database. ie. i ant to do something like this

char empname[100]

and then,

if (mysql_query(conn, "insert into empinfo values (empname)")) 
  {
      printf("4Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

but, this is storing NULL in the table.

is there any way to do this?
please help!

sorry i didn't post this part . after

char empname[100]

i ask the user for input

printf("please enter a employee name");
  fgets(empname,100,stdin);
  printf("%s",empname);

and then take this name in the code i have given earlier , but the name inputted by the user is not stored

isn't your SQL wrong, shouldn't it be

INSERT INTO empinfo (empname) VALUES ("???")

you will need to concatenate in the actual emp name instead of the ???

chrispadgham is correct.

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.