我正在尝试将数据插入到mysql数据库中,这是一个带验证的电子邮件注册。唯一的随机数未插入数据库表。请帮我。非常感谢。
else {
$user_confirm = md5(uniqid(rand()));
echo "$user_confirm";
//the form has been posted without, so save it
//notice the use of mysql_real_escape_string, keep everything safe!
//also notice the sha1 function which hashes the password
$sql = "INSERT INTO users(
user_name,
user_pass,
user_email,
user_date,
user_level,
user_confirm
)
VALUES('" . mysql_real_escape_string($_POST['user_name']) . "',
'" . sha1($_POST['user_pass']) . "',
'" . mysql_real_escape_string($_POST['user_email']) . "',
NOW(),
0,
'$user_confirm'
)";
$email = $_POST["user_email"];
$result = mysql_query($sql);
答案 0 :(得分:1)
您有两个问题:$user_confirm
是一个字符串(我使用您的代码生成beba256f79e888013bb34e5a774fe7f9
)并且您正在尝试将其存储在指定为整数的列中({{1 }})。
哈希字符串应存储在INT(11)
字段中,以允许TEXT
和md5()
生成的字符串大小。
其次,你真的不应该使用MD5密码哈希,你真的应该使用PHP的built-in functions来处理密码安全性。如果您使用的PHP版本低于5.5,则可以使用sha1()
compatibility pack。
Your script is at risk for SQL Injection Attacks.
如果可以,你应该stop using mysql_*
functions。已在PHP 7中删除These extensions。了解prepared和PDO的MySQLi语句,并考虑使用PDO,it's really pretty easy。
答案 1 :(得分:0)
MySQL md5函数返回32个十六进制数字的字符串,如果参数为NULL,则返回NULL。对字段使用varchar(32)而不是int(11)。
Refer to MySQL Document for more info.
另外,请确保正确地在字符串字段中添加引号。