0

我有一个将值插入 mySQL 表的 php 脚本

INSERT INTO stories (title) VALUES('$_REQUEST[title]);

我在进入表格之前检查了我的请求变量的值,这很好。

但是,例如,当我将 title=john 添加到表中时,

我得到这样 title = "[][][][]john" 的东西:当我提取值时,它是一个换行符,然后是 john.

我将列设置为 utf-8,我也尝试了瑞典字符集。

注意:从 phpMyAdmin 命令行插入值时,我没有收到此错误

4

3 回答 3

0

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()

于 2010-05-13T19:28:25.900 回答
0

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.

于 2010-05-13T19:32:48.180 回答
0

SET NAMES <encoding>每次连接到数据库时都必须执行查询。
非常简单的规则。

<encoding>mysql 方言中的 HTML 页面编码在哪里(对于utf8utf-8)

于 2010-05-13T19:21:53.480 回答