Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm getting the IP address from this statement and I want to pass the IP onto a SQL statement...Is this correct?

C#
int *addressValue = new int();
char *address = "192.168.1.103";
inet_pton(AF_INET, address, addressValue);
if (ip_header->source_ip != *addressValue)
{
    mysql_query(conn, "SelectCount(*) FROM tblURL WHERE IP = ip_header;source_ip And Status ='Active'");
}
Posted
Updated 23-Jul-11 9:06am
v2
Comments
Philippe Mori 23-Jul-11 15:07pm    
I have improved the formating a bit.

No. On so many levels...
SelectCount(*)
Needs at least one space - to separate SELECTfrom Count

"SelectCount(*) FROM tblURL WHERE IP = ip_header;source_ip And Status ='Active'"
Is a string. and as such will be passed though to MySql exactly as it is. MySql will then throw an error at you, because it does not recognize source_ip as a command (the ';' will terminate the select statement).

Concatenating text strings to make a Sql Satement is a recipe for disaster at the best of times: use parametrized queries instead.
 
Share this answer
 
Comments
Member 7766180 23-Jul-11 13:41pm    
How would I do that?
Member 7766180 24-Jul-11 9:49am    
Storing IP as an IP number as opposed to a string. Thanks for the heads up!
C#
sprintf(Query,"SELECT COUNT(*) FROM tblURL WHERE IP='%d' AND Status='Active'",(*addressValue));
Resource=mysql_query(conn,Query);


I wonder you dont know how to create a string................................

humm
 
Share this answer
 
Comments
Member 7766180 23-Jul-11 19:23pm    
humm...from what I'm gathering strings are bad. I'm now storing them as int(11) in the mysql, so now I guess I have to go from a string to an int?
Current info on source_ip
DWORD source_ip; // Source Address (32 bits)
char ipSrc[20], ipDest[20], thisIP[20];
printf("\n Source IP: %s", ipSrc);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900