dousong2967 2014-04-14 08:36
浏览 25

PHP登录后会更改帐户中的电子邮件地址

I am trying to enable a user to change their password on their account when logged in. However, I cant seem to get it to work.

Do you have any suggestions?

<?php

if ($_POST['submitEmail'])
{

 $newemail = $_POST['email'];
 $newemail = stripslashes($newemail);
 $newemail = str_replace("'", "&#39", "$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
}
?>
  • 写回答

1条回答 默认 最新

  • duandu1915 2014-04-14 08:44
    关注
    <input type ="button" value="submitEmail" onclick="verifyForm()"/>
    

    This has to be

    <input type="submit" value="submitEmail"/>
    

    Another error: Undefined $email:

    echo "<strong> Current Email: </strong>"; echo $email;
    

    has to be like this:

    echo "<strong> Current Email: </strong>"; echo $_POST['email'];
    

    Full version which works for me:

    <?php
    
    if ($_POST['submitEmail'])
    {
    
        $newemail = $_POST['email'];
        $newemail = stripslashes($newemail);
        $newemail = str_replace("'", "&#39", "$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
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向