我正在尝试制作一个表单,以便在php中登录并注册到网站。用户只能注册管理批准。在PHP中我发送一封电子邮件给管理员,其中包含激活码,但此代码无法正常工作。在用户表中,我有两行(ativo,代码)
register.php
require ("ligacaobd.php");
$user=$_POST['user'];
$pass=md5($_POST['pass']);
$email=$_POST['email'];
if($user && $email && $pass)
{
$confirmCode=rand();
$query=mysql_query("SELECT * FROM Utilizadores WHERE User='".$user."'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO Utilizadores(Id_user,Id_type,User,Email,Password,ativo,code) VALUES(NULL,'2','$user','$email','$pass','0','$confirmCode')";
$result=mysql_query($sql);
if($result)
{
echo "Thanks! Please wait for adminstration approval!";
}
else
{
echo "Failure!";
}
}
else
{
echo "That username already exists! Please try again with another.";
}
$search="SELECT * FROM Utilizadores WHERE Id_type='1'";
$result=mysql_query($search);
//
while($row=mysql_fetch_assoc($result))
{
$subject='New Account Request';
$from='... <...@gmail.com>';
$emailAdmin=$row["Email"];
$confirmUrl= 'http://.../php/confirm.php?user=$user&code=$confirmCode';
$message=" A new account has been requested with the following details:
Username: $user
Email: $email
Confirmation is required. Please click the link below to confirm registration:
$confirmUrl
Thanks";
mail($emailAdmin, $subject, $message, 'From: ' .$from);
}
和
confirm.php
$user=$_GET['user'];
$code=$_GET['code'];
$query=mysql_query("SELECT * FROM Utilizadores WHERE 'user'='$user'");
while($row=mysql_fetch_assoc($query))
{
$db_code=$row['confirmCode'];
}
if($code==$db_code)
{
mysql_query("UPDATE Utilizadores SET 'ativo'='1'");
mysql_query("UPDATE Utilizadores SET 'code'='0'");
echo "Thanks. Your email has been registered";
}
else
{
echo "Username and code don't match!";
}
错误:“用户名和代码不匹配!”
任何人都可以帮助我吗?