这个密码重置代码有什么问题?

时间:2011-12-23 23:10:23

标签: php html

<php
include 'connect.php';

// table name
$tbl_name="temp_members_db";

//Connect to server and select databse.
$db = mysql_connect($server, $username, $password) or die ("Unable to connect to Database Server.");
mysql_select_db ($database, $db) or die ("Could not select database.");

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

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

$name2="SELECT * FROM $tbl_name WHERE name ='$name'";
$name=mysql_query($name2);

$email2="SELECT * FROM $tbl_name WHERE email ='$email'";
$email=mysql_query($email2);

$password2="SELECT * FROM $tbl_name WHERE password ='$password'";
$password=mysql_query($password2);

$country2="SELECT * FROM $tbl_name WHERE country ='$country'";
$country=mysql_query($country2);

// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name2', '$email2', '$password2', '$country2')";
$result=mysql_query($sql);

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: Admin <admin@example.com>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.mindcollar.com/testconfirm.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}

?>

<table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form name="form1" method="post" action="signup_ac.php">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td colspan="3"><strong>Sign up</strong></td>
</tr>
<tr>
<td width="76">Name</td>
<td width="3">:</td>
<td width="305"><input name="name" type="text" id="name" size="30"></td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td>password</td>
<td>:</td>
<td><input name="password" type="password" id="password" size="30"></td>
</tr>
<tr>
<td>Country</td>
<td>:</td>
<td><input name="country" type="text" id="country" size="30"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> &nbsp;
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>

我正在尝试使用此注册页面然后是确认页面来创建密码重置脚本。但我遇到的问题是当我去“注册”没有任何反应,没有错误或结果。在表单填充后,我只是重定向到同一页面,只是表单重置,没有任何错误明智出现。

2 个答案:

答案 0 :(得分:0)

你有一些打字错误:

// values sent from form
$name=$_POST'name';
$email=$_POST'email';
$password=$_POST'password';
$country=$_POST'country';

应该是

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

希望这一切。

答案 1 :(得分:0)

重置代码没有问题。问题是您不需要从数据库中选择任何内容。试试这个:

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

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