0

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!

Edited by joy39: n/a

4
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by fobos
0

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

Edited by joy39: n/a

0

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 ???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.