Hi,
I have a form that contains data with Chinese characters. When it's
submited through http request, how can I write it to the database?
Currently I'm getting garbage when retrieve the records.
Here's code snippets:
contentTypeFromPost = getenv("CONTENT_TYPE");
contentTypeLength = getenv("CONTENT_LENGTH");
icontentLength = atoi(contentTypeLength);
if((queryString = malloc(icontentLength + 1)) == NULL)
{
postMessage("Cannot allocate memory", 0);
return(0);
}
...
for(i=0; *queryString; i++)
{
splitword(items.Item, queryString, '&');
unescape_url(items.Item);
splitword(items.name, items.Item, '=');
if(!strcmp(items.name, "Name"))
{
strcpy(name, items.Item);
}
else if(!strcmp(items.name, "Address"))
{
strcpy(address, items.Item);
}
...
sprintf(query_string, "INSERT INTO info values('%s', '%s')", name,
address);
res = PQexec(conn, query_string);
name & address are in Chinese.
Do I have to do any conversion before writing to the database?
-Jeff