Hello,
I am doing programming in C and uses MySQL database. I have got a problem with
inserting "values stored in variables" to the database. When compiling the code
that I have written the following error message shows up:
connect2.c: In function `main':
connect2.c:19: invalid operands to binary +
The code that I have written is given below. Please give a solution.
Thanks in advance,
Preeth.
#include
#include
#include
#include
int main(int argc, char *argv[])
{
MYSQL my_connection;
int res;
char srcip[13]="172.16.4.200";
char destip[13]="172.16.4.220";
int srcport=20;
int destport=30;
mysql_init(&my_connection);
if(mysql_real_connect(&my_connection,"LocalHost","root","master","project",0,NULL,0))
{
printf("Connection Success\n");
/***Insert
Query***/
res=mysql_query(&my_connection,"INSERT INTO
ids(sip,sport,dip,dport)VALUES('"+srcip+"',"+srcport+",'"+destip+"',"+destport+")");
if (!res)
{
printf("Inserted %lu rows\n",(unsigned
long)mysql_affected_rows(&my_connection));
}
else
{
fprintf(stderr,"Insert error %d:
%s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
mysql_close(&my_connection);
}
else
{
fprintf(stderr,"Connection Failed\n");
if (mysql_errno(&my_connection))
{ fprintf(stderr,"Connection error %d:
%s\n",mysql_errno(&my_connection),mysql_error(&my_connection));
}
}
return EXIT_SUCCESS;
}
/***/