愿你们平安,我正在开发一个“忘记用户名”系统,我的代码如下所示:-
第一种形式:-
`<form action="security.php" method="post">
Please Enter your email address:<br>
<input type="text" name="email" value="<?php $_POST['email']?>">
<input type="submit" value="submit">
</form>`
php代码:
`<?php
$mode_allowed = array('username','password');
if(isset($_GET['mode']) === true && in_array($_GET['mode'],$mode_allowed) === true){
if(isset($_POST['email']) === true && empty($_POST['email']) === false){
if(email_exists($_POST['email']) === true){
header('location:security.php');
}else{
echo "Sorry, we can't find this email";
}
}
}else{
header('location:index.php');
}
?>`
现在另一个页面:
<form action="security.php" method="POST">
<p> Answer this question <p>
<select type="text" selected="selected" name="security_question" value="<?php $security_question?>">
<option name="security_question" value="<?php $security_question =mysql_query("SELECT `security_question` FROM `users` WHERE `email`='".mysql_real_escape_string($_POST['email'])."' ");
$array = mysql_fetch_array($security_question);
echo $array[0];
?>">
<?php $security_question =mysql_query("SELECT `security_question` FROM `users` WHERE `email`='".mysql_real_escape_string($_POST['email'])."' ");
$array = mysql_fetch_array($security_question);
echo $array[0];
?>
</option> </select> <br>
<input type="text" name="answer"/> <br>
<input type="submit" value="recover"/>
</form>
及其PHP:
<?php
include "session.php";
include "database/db.php";
if(isset($_POST['answer'])){
$answer = $_POST['answer'];
if(!empty($answer)){
$sql = mysql_query("SELECT `username` FROM `users` WHERE `email`='".mysql_real_escape_string($_POST['email'])."' AND `answer`='".mysql_real_escape_string($answer)."'");
if(mysql_num_rows($sql) == 1){
echo"hello";
}else {
echo "no";
}
}else{
echo "<script type='text/javascript'>alert('you must answer this question');</script>";
}
}
?>
我还为电子邮件添加了一个隐藏字段:-
<input type="hidden" name="email" value="<?php echo $_POST['email'];?>">
现在,只有当我从 SQL 语句中删除“电子邮件”部分时,代码才能完美运行!这里有什么错误?!