duanshan3065 2015-01-03 14:49
浏览 31

更改用户名不起作用

I'm trying to code a change username for my users on my site. The problem is that when I try to change my username, all it does is detele my user out of the database.

<?php
        $captcha = 'xb33ssa1';

    function gen_token($pass, $salt) {
        $salt = strtolower($salt);
        $str = hash("sha512", $pass.$salt);
        $len = strlen($salt);
        return strtoupper(substr($str, $len, 17));
    }

    $username = $_SESSION['username'];
    $current = $_POST['currentpassword'];
    $newuser = $_POST['newusername'];
    $veriuser = $_POST['verifyusername'];
    $current = stripslashes($current);
    $newuser= stripslashes($newuser);
    $veriuser = stripslashes($veriuser);
    $current = mysql_real_escape_string($current);
    $newuser = mysql_real_escape_string($newuser);
    $veriuser = mysql_real_escape_string($veriuser);
    $current = gen_token($current, $username);
    $newuser = gen_token($newuser, $username);
    $veriuser = gen_token($veriuser, $username);

    if(isset($_POST['currentpassword']) || isset($_POST['newusername']) || isset($_POST['verifyusername'])) {
        if($_POST['newusername']==$_POST['verifyusername']) {
            if(!empty($_POST['currentpassword']) || !empty($_POST['newusername']) || !empty($_POST['verifyusername'])) {
                if($veriuser==$newuser) {
                    $con = mysql_query("SELECT * from meh_users WHERE Password='$current' && Username='$username'");
                    $count = mysql_num_rows($con);
                    if($count>0) {
                        if($_POST['captcha']==$captcha) {
                            $status = '<center>You have successfully changed your username!</center>';
                            $boxkind = 'success';
                            mysql_query("UPDATE meh_users SET Username='$newuser' WHERE Username='$username'");
                        } else {
                            $status = '<center>The captcha you entered does not match on the given captcha!</center>';
                            $boxkind = 'danger';
                            }
                        } else {
                            $status = '<center>The password you entered does not match on the password you currently have.</center>';
                            $boxkind = 'danger';
                        }
                    } else {
                        $status = '<center>The username you entered for your new and the verification of the new username does not match.</center>';
                        $boxkind = 'danger';
                    }
                } else {
                    $status = '<center>Some fields remains empty, please fill every field, for they are all important.</center>';
                    $boxkind = 'danger';
                }
            } else {
                $status = '<center>The password you entered for your new and the verification of the new password does not match.</center>';
                $boxkind = 'danger';
            }
        } else {
            $status = '<center>Please fill in the prerequisites below. Please be notified that you can not retrieve your Username once you have forgotten your new one.</center>';
            $boxkind = 'info';
        }
?>
         <!-- BEGIN PAGE HEADER-->
         <div class="row">
            <div class="col-md-12">
               <!-- BEGIN PAGE TITLE & BREADCRUMB-->
               <h3 class="page-title">
                  Change Username <small></small>
               </h3>
               <ul class="page-breadcrumb breadcrumb">
                  <li>
                     <i class="icon-home"></i>
                     Account Manager
                     <i class="icon-angle-right"></i>
                  </li>
                  <li>Change Username</li>
               </ul>
               <!-- END PAGE TITLE & BREADCRUMB-->
            </div>
         </div>
         <!-- END PAGE HEADER-->
         <!-- END DASHBOARD STATS -->

                      <div class="tab-content">
                      <div class="tab-pane active" id="tab_0">
                        <div class="portlet box green">
                           <div class="portlet-title">
                              <div class="caption"><i class="icon-reorder"></i> Change your Username:</div>
                              </div>
                           </div>
                         <div class="alert alert-<?php echo $boxkind; ?> alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
                            <?php echo $status; ?>
                         </div>
                           <div class="portlet-body form">
                              <!-- BEGIN FORM-->
                              <form action="../vipdailyreward" method="POST" class="form-horizontal">
                                 <div class="form-body">
                                    <div class="form-group">
                                       <label  class="col-md-3 control-label">Current Password</label>
                                       <div class="col-md-4">
                                          <div class="input-group">
                                             <input type="password" class="form-control" placeholder="Current Password" name="currentpassword">
                                             <span class="input-group-addon"><i class="icon-user"></i></span>
                                          </div>
                                       </div>
                                    </div>
                                    <div class="form-group">
                                       <label  class="col-md-3 control-label">New Username</label>
                                       <div class="col-md-4">
                                          <div class="input-group">
                                             <input type="text" class="form-control" placeholder="New Username" name="newusername">
                                             <span class="input-group-addon"><i class="icon-user"></i></span>
                                          </div>
                                       </div>
                                    </div>
                                    <div class="form-group">
                                       <label  class="col-md-3 control-label">Verify Username</label>
                                       <div class="col-md-4">
                                          <div class="input-group">
                                             <input type="text" class="form-control" placeholder="Verify Username" name="verifyusername">
                                             <span class="input-group-addon"><i class="icon-user"></i></span>
                                          </div>
                                       </div>
                                    </div>
                                    <div class="form-group">
                                       <label  class="col-md-3 control-label">Captcha:</label>
                                       <div class="col-md-4">
                                          <div class="input-group">
                                             <input type="text" class="form-control" placeholder="Type: <?php echo $captcha; ?>" name="captcha">
                                          </div><br />
                                       </div>
                                    </div>
                                 </div>
                                 <div class="form-actions fluid">
                                    <div class="col-md-offset-3 col-md-9">
                                       <input type="submit" class="btn blue" name="submit"></input>
                                       <input type="reset" class="btn default" value="Clear"></input>   
                                    </div>
                                 </div>
                              </form>
                              <!-- END FORM--> 
                           </div>
                        </div>
         </div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c