如何包含“@”或“。”等字符。在MySQL表中?

时间:2011-05-24 21:57:01

标签: php mysql database wildcard

当用户注册某个站点并在用户名中包含空格,句点或@时,它似乎会产生问题。我怎样才能包含这些字符?

1 个答案:

答案 0 :(得分:4)

MySQL不会关心用户名或密码中的字符,除非您没有正确构建查询:

$password = $_POST['password'];
$username = $_POST['username'];

$quoted_pass = mysql_real_escape_string($password);
$quoted_user = mysql_real_escape_string($username);

$sql = "INSERT INTO users (username, password) VALUES ('$quoted_pass', '$quoted_user');
$result = mysql_query($sql) or die(mysql_error());

if (mysql_affected_rows($result) != 1) {
   die("User record not created");
}