Hi everyone! I recently created a MySQL table that has three columns:
(1) integer ID (2) integer num1 (3) integer num2
Now, I have a C program that waits for the user to input an integer ID and when there is an input, the corresponding num1 and num2 in the 2nd and 3rd columns in the table will be retrieved. However, it only assumes that the input is in the table. I don't know yet how to include an error checking part in the code that will determine whether the inputted value is contained in the table or not. If the input is not in the table, I should inform the user that the input was invalid. Could anyone give me an idea how to implement this error checking? I'm using C program in Windows XP. Answers will be greatly appreciated.
My current program looks like the one below:
void command2(MYSQL *conn, int value) {
int col1, col2;
MYSQL_RES *res;
MYSQL_ROW row;
char cmd2[1024] = "";
snprintf(cmd2,sizeof(cmd2),"select num1, num2 from table3 where ID = %d", value);
if (mysql_query(conn, cmd2)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
while((row = mysql_fetch_row(res)) != NULL) {
col1 = atoi((const char *) row[0]);
col2 = atoi((const char *) row[1]);
}
mysql_free_result(res);
}