我正在尝试让用户在登录时更改其帐户的密码。但是,我似乎无法让它工作。
你有什么建议吗?
<?php
if ($_POST['submitEmail'])
{
$newemail = $_POST['email'];
$newemail = stripslashes($newemail);
$newemail = str_replace("'", "'", "$newemail");
//checks database to see if email user types in already exists
$query = "SELECT * FROM users WHERE email = '$newemail'";
$result = mysqli_query($db_connection, $query);
$nums = mysqli_num_rows($result);
if ($nums >= 1)
{
//if email already exists, inform user
echo "Email already exists";
echo "<br/>Click <a href = 'account.php?page=email'> HERE</a> to try again";
}
else
{
//if email does not already exist, update users email
$querychange = "UPDATE users SET email = '$newemail' where id = '$userID'";
$result3 = mysqli_query($db_connection, $querychange);
echo "Your Email has been changed";
}
}
else {
echo "<strong> Current Email: </strong>$email ";
?>
<!-- Allows users to enter new email address -->
<form name="changeEmail" id="changeEmail" method="post" action="account.php?page=email">
<input type="hidden" value="email" name="account_submit_type"/>
<input type='hidden' name='changeEmail' value='yes'>
<strong> Email </strong><input type = "text" name = "email" size="40" value=""> <br>
<input type ="button" value="submitEmail" onclick="verifyForm()"/>
</form>
<?php
}
?>
答案 0 :(得分:1)
<input type ="button" value="submitEmail" onclick="verifyForm()"/>
这必须是
<input type="submit" value="submitEmail"/>
另一个错误:未定义的$ email:
echo "<strong> Current Email: </strong>"; echo $email;
必须是这样的:
echo "<strong> Current Email: </strong>"; echo $_POST['email'];
适用于我的完整版:
<?php
if ($_POST['submitEmail'])
{
$newemail = $_POST['email'];
$newemail = stripslashes($newemail);
$newemail = str_replace("'", "'", "$newemail");
//checks database to see if email user types in already exists
$query = "SELECT * FROM users WHERE email = '$newemail'";
$result = mysqli_query($db_connection, $query);
$nums = mysqli_num_rows($result);
if ($nums >= 1)
{
//if email already exists, inform user
echo "Email already exists";
echo "<br/>Click <a href = 'account.php?page=email'> HERE</a> to try again";
}
else
{
//if email does not already exist, update users email
$querychange = "UPDATE users SET email = '$newemail' where id = '$userID'";
$result3 = mysqli_query($db_connection, $querychange);
echo "Your Email has been changed";
}
}
else {
echo "<strong> Current Email: </strong>"; echo $_POST['email'];
?>
<!-- Allows users to enter new email address -->
<form name="changeEmail" id="changeEmail" method="post" action="#?page=email">
<input type="hidden" value="email" name="account_submit_type"/>
<input type='hidden' name='changeEmail' value='yes'>
<strong> Email </strong><input type = "text" name = "email" size="40" value=""> <br>
<input type="submit" value="submitEmail"/>
</form>
<?php
}
?>