在php中使用md5()函数后密码不加密

时间:2014-05-08 05:17:06

标签: php mysql encryption md5

我尝试使用php中的md5()函数加密我的登录密码。我遵循了http://www.phpeasystep.com/workshopview.php?id=26的教程,但密码在我的数据库中仍然可读。我使用了这段代码,

$host="localhost";
$username="root";
$password="";
$db_name="database";
$tbl_name="members";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name") or die(mysql_error());

// POST values from form
$name=$_POST['name'];
$email=$_POST['email'];
$password=$_POST['password'];

// encrypt password 
$encrypted_password=md5($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$encrypted_password'";
$result=mysql_query($sql);

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(name, email, password)VALUES('$name', '$email', '$password')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Your account had been created..!";
echo "<BR>";
echo "<a href='login.php'>Login to continue</a>";
}

else {
echo "There's an error. Why don't you try again? it may be temporary.";
}

请帮帮我......

1 个答案:

答案 0 :(得分:0)

这个怎么样?

$sql="INSERT INTO $tbl_name(name, email, password)VALUES('$name', '$email', '$encrypted_password')";
$result=mysql_query($sql);