The users may input some special chars in the input box:
<input type="text" name="task_description" id="task_description" value="<?cs var:Query.task_description?>">
double quotation marks and single quotation marks for example. I need to get their input text and insert the task_description into my database table.
On my server, I write my cgi using C++, and my database is mySQL.
the user's input will be transferred to the server in JSON.
the problem is on the server side, when I want to get the strings input by the users in
JSON, I just can not get the right one. for example:
if the user input:
hello " " hello
on the server side I get the input string in the JSON like this:
static string get_escape_string(const string& src)
{
static char escape_buffer[1024*1024];
mysql_escape_string(escape_buffer, src.c_str(), src.length());
string dst(escape_buffer, strlen(escape_buffer));
return dst;
}
//here is how I get the user's input
string remarks = get_escape_string(record[i]["remarks"].asString());
the "record" is the JSON data, after the operation I can only get: hello
it is truncated at the first double quoation mark.
I tried to use the function "escape" in the front end javascript code, but "escape" can not
code double quotation mark.
How could I deal with the double and single quotation marks?
thanks in advance!