| | |
server notify client to update MySQL table
![]() |
•
•
Join Date: Jul 2006
Posts: 32
Reputation:
Solved Threads: 0
Hi All,
I've write a code for client and server. It works well so far but the server just acknowledge the client of what it received. How to recode this program to make sure that once server acknowledged the client that the data sent by the client have been append in the file in the server machine so that client program can update the status of that particluar MySQL table? I've write the code but the status didnt update as what I want and I also cant compile this program. The error is: client.c:65: error: incompatible types in assignment
Below are the code:
Need any help from expert here..thanks
I've write a code for client and server. It works well so far but the server just acknowledge the client of what it received. How to recode this program to make sure that once server acknowledged the client that the data sent by the client have been append in the file in the server machine so that client program can update the status of that particluar MySQL table? I've write the code but the status didnt update as what I want and I also cant compile this program. The error is: client.c:65: error: incompatible types in assignment
Below are the code:
C Syntax (Toggle Plain Text)
#include <mysql.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <string.h> #include <stdlib.h> void error(char *msg) { perror(msg); exit(0); } int main(int argc, char *argv[]) { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *host = "192.168.2.11"; char *user = "daily1a"; char *password = "daily2006"; char *database = "28882db"; char string1[500], query[500], Tid[50]; void senddata(char *SendString); conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } /* send SQL query */ if (mysql_query(conn, "SELECT MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } res = mysql_use_result(conn); /* output fields 0, 1 and 2 of each row */ while ((row = mysql_fetch_row(res)) != NULL) { bzero(string1, sizeof(string1)); sprintf(string1,"%s,%s,%s", row[0], row[1], row[2]); printf ("%s\n",string1); senddata(string1); } if (row[9]==0) { bzero(query, sizeof(query)); Tid = atoi(row[0]); sprintf(query, "UPDATE Subscriptions SET Status = 1 WHERE MobileNumber = '%s'",Tid); } /* Release memory used to store results and close connection */ mysql_free_result(res); mysql_close(conn); return 0; } void senddata(char *SendString) { char buf[8192]; char message[256]; int socket_descriptor; struct sockaddr_in pin; struct hostent *server_host_name; char * host_name = "127.0.0.1"; int port = 8000; char * str = "A default test string"; str = SendString; if ((server_host_name = gethostbyname(host_name)) == 0) { perror("Error resolving local host\n"); exit(1); } bzero(&pin, sizeof(pin)); pin.sin_family = AF_INET; pin.sin_addr.s_addr = htonl(INADDR_ANY); pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr; pin.sin_port = htons(port); if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Error opening socket\n"); exit(1); } if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) { perror("Error connecting to socket\n"); exit(1); } printf("Sending message %s to server...\n", str); if (send(socket_descriptor, str, strlen(str), 0) == -1) { perror("Error in send\n"); exit(1); } printf("...Sent message.. wait for response...\n"); if (recv(socket_descriptor, buf, 8192, 0) == -1) { perror("Error in receiving response from server\n"); exit(1); } printf("\nResponse from server:\n\n%s\n", buf); close(socket_descriptor); }
Need any help from expert here..thanks
•
•
•
•
#include <mysql.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <string.h> #include <stdlib.h> void error(char *msg) { perror(msg); exit(0); } int main(int argc, char *argv[]) { MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *host = "192.168.2.11"; char *user = "daily1a"; char *password = "daily2006"; char *database = "28882db"; char string1[500], query[500], Tid[50]; void senddata(char *SendString); conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } /* send SQL query */ if (mysql_query(conn, "SELECT MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } res = mysql_use_result(conn); /* output fields 0, 1 and 2 of each row */ while ((row = mysql_fetch_row(res)) != NULL) { bzero(string1, sizeof(string1)); sprintf(string1,"%s,%s,%s", row[0], row[1], row[2]); printf ("%s\n",string1); senddata(string1); } if (row[9]==0) { bzero(query, sizeof(query)); // Tid = atoi(row[0]); sprintf(query, "UPDATE Subscriptions SET Status = 1 WHERE MobileNumber = '%s'",Tid); } /* Release memory used to store results and close connection */ mysql_free_result(res); mysql_close(conn); return 0; } void senddata(char *SendString) { char buf[8192]; char message[256]; int socket_descriptor; struct sockaddr_in pin; struct hostent *server_host_name; char * host_name = "127.0.0.1"; int port = 8000; char * str = "A default test string"; str = SendString; if ((server_host_name = gethostbyname(host_name)) == 0) { perror("Error resolving local host\n"); exit(1); } bzero(&pin, sizeof(pin)); pin.sin_family = AF_INET; pin.sin_addr.s_addr = htonl(INADDR_ANY); pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr; pin.sin_port = htons(port); if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Error opening socket\n"); exit(1); } if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) { perror("Error connecting to socket\n"); exit(1); } printf("Sending message %s to server...\n", str); if (send(socket_descriptor, str, strlen(str), 0) == -1) { perror("Error in send\n"); exit(1); } printf("...Sent message.. wait for response...\n"); if (recv(socket_descriptor, buf, 8192, 0) == -1) { perror("Error in receiving response from server\n"); exit(1); } printf("\nResponse from server:\n\n%s\n", buf); close(socket_descriptor); }
Also row is a array of char pointers and in your above code you are comparing
row [9] with an integer value 0.Make it necessary changes and see if it works.
HOpe it helped, bye.
I don't accept change; I don't deserve to live.
•
•
Join Date: Jul 2006
Posts: 32
Reputation:
Solved Threads: 0
Hi,
I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors:
client.c: In function senddata:
client.c:147: error: incompatible implicit declaration of function UpdateStatus
client.c:37: error: previous implicit declaration of UpdateStatus was here
The code is as below:
Supposedly, this program..after receiving response from server, this client program should update MySQL table.
Thanks
I've made some changes to my coding..but unfortunately, there were errors when compiling it..dunno how to solve it..hope anyone can help me...the errors:
client.c: In function senddata:
client.c:147: error: incompatible implicit declaration of function UpdateStatus
client.c:37: error: previous implicit declaration of UpdateStatus was here
The code is as below:
C Syntax (Toggle Plain Text)
#include <mysql.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <string.h> #include <stdlib.h> MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; char *host = "192.168.2.11"; char *user = "daily1a"; char *password = "daily2006"; char *database = "28882db"; int tbuf; void error(char *msg) { perror(msg); exit(0); } int main(int argc, char *argv[]) { char string1[500], query[500], transid[50]; int i, j; void senddata(char* SendString, char* transID); //void senddata(char *SendString, *transID); //void UpdateStatus(char *transID); void UpdateStatus(char transID[100]); void timebuffer(); conn = mysql_init(NULL); j=1; while (j=1) { /* Connect to database */ if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } /* send SQL query */ if (mysql_query(conn, "SELECT TransID, MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } res = mysql_use_result(conn); /* output fields 0, 1 and 2 of each row */ while ((row = mysql_fetch_row(res)) != NULL) { if (i==11) { timebuffer(); i=1; bzero(string1, sizeof(string1)); } else { //transid = row[0]; sprintf(string1,"%s,%s,%s,%s", row[0], row[1], row[2], row[3]); printf ("%s\n",string1); senddata(string1, transid); i++; } } } /* Release memory used to store results and close connection */ mysql_free_result(res); mysql_close(conn); return 0; } void senddata(char* SendString, char* transID) { char buf[8192]; //char *update; char message[256]; int socket_descriptor; struct sockaddr_in pin; struct hostent *server_host_name; char * host_name = "127.0.0.1"; int port = 8000; char * str = "A default test string"; char * trans = "123456"; str = SendString; trans = transID; if ((server_host_name = gethostbyname(host_name)) == 0) { perror("Error resolving local host\n"); exit(1); } bzero(&pin, sizeof(pin)); pin.sin_family = AF_INET; pin.sin_addr.s_addr = htonl(INADDR_ANY); pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr; pin.sin_port = htons(port); if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("Error opening socket\n"); exit(1); } if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) { perror("Error connecting to socket\n"); exit(1); } printf("Sending message %s to server...\n", str); if (send(socket_descriptor, str, strlen(str), 0) == -1) { perror("Error in send\n"); exit(1); } printf("...Sent message.. wait for response...\n"); if (recv(socket_descriptor, buf, 8192, 0) == -1) { perror("Error in receiving response from server\n"); exit(1); } printf("\nResponse from server:\n\n%s\n", buf); UpdateStatus(TransID); //update=buf; //UpdateStatus(update); close(socket_descriptor); } void UpdateStatus(char transID[100]) { char query[2000]; char query1[2000]; char id; char TransID; conn = mysql_init(NULL); /* Connect to database */ if (!mysql_real_connect(conn, host, user, password, database, 0, NULL, 0)) { fprintf(stderr, "%s\n", mysql_error(conn)); exit(0); } bzero(query1, sizeof(query1)); id = atoi(TransID); sprintf(query1, "UPDATE Subscriptions SET Status = 1 WHERE TransID = '%s'",id); #ifdef DEBUG printf("%s\n",query1); #endif /* Release memory used to store results and close connection */ mysql_free_result(res); mysql_close(conn); } void timebuffer() { struct timeval tv; tv.tv_sec=tbuf; tv.tv_usec=0; #ifdef TRACE printf ("time buffer: %d\n", tv.tv_sec); #endif select (0,0,0,0,&tv); }
Supposedly, this program..after receiving response from server, this client program should update MySQL table.
Thanks
![]() |
Similar Threads
- how to update data in mysql table using data from an excel table (MySQL)
- Apache (Linux Servers and Apache)
- Automate Data from text file into MySql table? (MySQL)
- Using MySQL with PHP - Tutorial by Herong (MySQL)
- ERROR 2002: Can't connect to local MySQL server (MySQL)
- Multi-user program issues (VB.NET)
Other Threads in the C Forum
- Previous Thread: why should we always use "CALLBACK" and "WINAPI" these words
- Next Thread: Why this C code is returning Null Pointer Assignment as output
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






