Sir,

I am facing problem in one function , actually in my table there is two field: id, and password and I am checking the id field for any user who is added to the friendlist of another user, like in yahoo messenger.

MYSQL *conn;
MYSQL_RES *res_ptr;
MYSQL_ROW sqlrow;
FILE *fp;
/******************************************************/

int Friend_Result()
{
unsigned int i; int rows;

while( (sqlrow = mysql_fetch_row(res_ptr)) != NULL)
{

for(i = 0; i < mysql_num_fields(res_ptr); i++)
{
if(i > 0) printf("\t");

if(sqlrow[i] != NULL) printf("%s", sqlrow[i]);
else printf("%s", "NULL");
}
printf("\n");
}
if(mysql_errno(conn) != 0)
{
printf("mysql_fetch_row error\n");
return 0;
}
if((unsigned long)mysql_num_rows(res_ptr) == 0)
{

printf("Invalid .... Not have a valid TARA ID...\n");
return 0;
}
return 1;
}
/******************************************************/

int Check_Exist_Friend(char *f)
{
char buf[200];
int result, rows;

printf(" Friend = %s\n", f);
strcpy(buf, "SELECT id from tara_user where id = ");
strcat(buf, "'");
strcat(buf, f);
strcat(buf, "'");

result = mysql_query(conn, buf);

res_ptr = mysql_store_result(conn);

if(res_ptr == NULL) printf("Storing Error\n");
else
{
printf("Res_ptr is not null\n");
if(! Friend_Result() ) return 0;
mysql_free_result(res_ptr);
}
return 1;
}

/************* CHECK THE FRIEND - ID IN DATABASE ***********/

void Add_New_Friend(char *a, char *gp, char *f, int sd)
{
int result;
char buf[200];

printf("Friend name = %s\n", f);
if(! Check_Exist_Friend(f) ) return;
else
{
strcpy(buf, "INSERT INTO flist values(");
strcat(buf, "'");
strcat(buf, a);
strcat(buf, "'");
strcat(buf, ",");
strcat(buf, "'");
strcat(buf, gp);
strcat(buf, "'");
strcat(buf, ",");
strcat(buf, "'");
strcat(buf, f);
strcat(buf,"'");
strcat(buf,")");

result = mysql_query(conn, buf);

if(!result) printf("Inserted %lu rows\n",
(unsigned long)mysql_affected_rows(conn));
else fprintf(stderr, "Insert error %d: %s\n", mysql_errno(conn),
mysql_error(conn));
}
}

I am calling function Check_Exist_Friend(f) from Add_New_Friend() but each time where the friend name is existing in the table or not it give me the same result. I have tried a lot but couldn't succeed.
I don't know where is fault , so please reply me ..... so that I can do my rest of work.

If there are other option to check the existence of any user whether the user is present or not , please let me know....

Hoping positive response from your side.

Thanking you

ASHOK KUMAR
M.C.A. 5TH SEM.
COCHIN UNIVERSITY OF SCIENCE AND TECHNOLOGY
KOCHI : 682 022, KERALA (INDIA).

________________________________________________________________
NIIT supports World Computer Literacy Day on 2nd December.
Enroll for NIIT SWIFT Jyoti till 2nd December for only Rs. 749
and get free Indian Languages Office software worth Rs. 2500.
For details contact your nearest NIIT centre, SWIFT Point
or click here http://swift.rediff.com/




---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to