开发者

mysql - funny square characters added to the value when inserting it into table

I have a php script that inserts values into mySQL table

INSERT INTO stories (title) VALUES('$_REQUEST[title]);开发者_JS百科

I checked the values of my request variables before going into the table and it's fine.

But when I add title=john to the table for example,

I get something like this: title = "[][][][]john" and when I extract the value, it's a newline then john.

I have my columns set to utf-8, I tried swedish character set as well.

Note: I don't get this error when inserting values from the phpMyAdmin commandline


You need {} around any array notation when used inside "".

$q="INSERT INTO stories(title) VALUES('{$_REQUEST['title']}')";

BTW, it would be better, when checking your $_REQUEST vars to store the sanitized versions in new variables, and to be sure to escape them with real_escape_string()


SET NAMES <encoding> query must be executed every time you connect to your database.
very simple rule.

where <encoding> is your HTML page encoding in mysql dialect (utf8 for the utf-8)


You need to check the character set of the database, the server, and the client.

Note that it's not a swedish character set, it's a swedish collation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜