if ($num1 || $num2) {
die("OVER2");
echo "<script>alert('该用户名已被人使用。');history.go(-1);</script>";
}else {
$db->dealsqlfunc($SQL5);
$db->close();
echo "<script>alert('注册成功');location.href='nocheck.php';</script>" ;
}
第一步:判断当前输入的会员名称是否有重复
第二步:如果正常就可以将数据保存到数据表中去!
我测试的时候发现,数据已经插入到数据库中去了。但是怎么总会 又提示我 “用户名已被人使用”
其中:
$num1 = $db->isExistsRecord($SQL1);
$num2 = $db->isExistsRecord($SQL2);function isExistsRecord($sql) {
$res = $this->query($sql);
$num_rows = mysql_num_rows($res);
return $num_rows;
}
$SQL1 = "SELECT ZH_ID FROM zh_register WHERE zh_name = '".$value."'";
$SQL2 = "SELECT ZH_ID FROM zh_user WHERE zh_name = '".$value."'"; #会员表验证
$value = strip_tags(substr($_POST['reg_username'],0,32));问题我觉得就是:当插入数据表之后又马上执行此验证页面!不知道是什么原因望高手帮我解答下谢谢了

解决方案 »

  1.   

    /* 注册会员的处理 */
    elseif ($action == 'act_register')
    {
        /* 增加是否关闭注册 */
        if ($_CFG['shop_reg_closed'])
        {
            $smarty->assign('action',     'register');
            $smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
            $smarty->display('user_passport.dwt');
        }
        else
        {
            include_once(ROOT_PATH . 'includes/lib_passport.php');        $username = isset($_POST['username']) ? trim($_POST['username']) : '';
            $password = isset($_POST['password']) ? trim($_POST['password']) : '';
            $email    = isset($_POST['email']) ? trim($_POST['email']) : '';
            $other = isset($_POST['other']) ? $_POST['other'] : array();
            $back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';        if(empty($_POST['agreement']))
            {
                show_message($_LANG['passport_js']['agreement']);
            }
            if (strlen($username) < 3)
            {
                show_message($_LANG['passport_js']['username_shorter']);
            }        if (strlen($password) < 6)
            {
                show_message($_LANG['passport_js']['password_shorter']);
            }        /* 验证码检查 */
            if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
            {
                if (empty($_POST['captcha']))
                {
                    show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'user.php?act=register', 'error');
                }            /* 检查验证码 */
                include_once('includes/cls_captcha.php');            $validator = new captcha();
                if (!$validator->check_word($_POST['captcha']))
                {
                    show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'user.php?act=register', 'error');
                }
            }        if (register($username, $password, $email, $other) !== false)
            {
                /*把新注册用户的扩展信息插入数据库*/
                $sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' ORDER BY id';   //读出所有扩展字段的id
                $fields_arr = $db->getAll($sql);            $extend_field_str = '';    //生成扩展字段的内容字符串
                foreach ($fields_arr AS $val)
                {
                    $extend_field_index = 'extend_field' . $val['id'];
                    if(!empty($_POST[$extend_field_index]))
                    {
                        $temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index];
                        $extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . $temp_field_content . "'),";
                    }
                }
                $extend_field_str = substr($extend_field_str, 0, -1);            if ($extend_field_str)      //插入注册扩展数据
                {
                    $sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str;
                    $db->query($sql);
                }            $ucdata = empty($user->ucdata)? "" : $user->ucdata;
                


    show_message(sprintf($_LANG['register_success'], $username . $ucdata), array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act, 'user.php'), 'info');
            }
            else
            {
                $err->show($_LANG['sign_up'], 'user.php?act=register');
            }
        }
    }/* 验证用户注册邮件 */
    elseif ($action == 'validate_email')
    {
        $hash = empty($_GET['hash']) ? '' : trim($_GET['hash']);
        if ($hash)
        {
            include_once(ROOT_PATH . 'includes/lib_passport.php');
            $id = register_hash('decode', $hash);
            if ($id > 0)
            {
                $sql = "UPDATE " . $ecs->table('users') . " SET is_validated = 1 WHERE user_id='$id'";
                $db->query($sql);
                $sql = 'SELECT user_name, email FROM ' . $ecs->table('users') . " WHERE user_id = '$id'";
                $row = $db->getRow($sql);
                show_message(sprintf($_LANG['validate_ok'], $row['user_name'], $row['email']),$_LANG['profile_lnk'], 'user.php');
            }
        }
        show_message($_LANG['validate_fail']);
    }/* 验证用户注册用户名是否可以注册 */
    elseif ($action == 'is_registered')
    {
        include_once(ROOT_PATH . 'includes/lib_passport.php');    $username = trim($_GET['username']);
        $username = json_str_iconv($username);    if ($user->check_user($username) || admin_registered($username))
        {
            echo 'false';
        }
        else
        {
            echo 'true';
        }
    }/* 验证用户邮箱地址是否被注册 */
    elseif($action == 'check_email')
    {
        $email = trim($_GET['email']);
        if ($user->check_email($email))
        {
            echo 'false';
        }
        else
        {
            echo 'ok';
        }
    }
    /* 用户登录界面 */
    elseif ($action == 'login')
    {
        if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
        {
            $back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
        }
        else
        {
            $back_act = 'user.php';
        }    $captcha = intval($_CFG['captcha']);
        if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
        {
            $GLOBALS['smarty']->assign('enabled_captcha', 1);
            $GLOBALS['smarty']->assign('rand', mt_rand());
        }    $smarty->assign('back_act', $back_act);
        $smarty->display('user_passport.dwt');
    }/* 处理会员的登录 */
    elseif ($action == 'act_login')
    {
        $username = isset($_POST['username']) ? trim($_POST['username']) : '';
        $password = isset($_POST['password']) ? trim($_POST['password']) : '';
        $back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';
        $captcha = intval($_CFG['captcha']);
        if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
        {
            if (empty($_POST['captcha']))
            {
                show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
            }        /* 检查验证码 */
            include_once('includes/cls_captcha.php');        $validator = new captcha();
            $validator->session_word = 'captcha_login';
            if (!$validator->check_word($_POST['captcha']))
            {
                show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
            }
        }    if ($user->login($username, $password))
        {
            update_user_info();
            recalculate_price();        $ucdata = isset($user->ucdata)? $user->ucdata : '';
            show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
        }
        else
        {
            $_SESSION['login_fail'] ++ ;
            show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
        }
    }
      

  2.   

    /* 处理 ajax 的登录请求 */
    elseif ($action == 'signin')
    {
        include_once('includes/cls_json.php');
        $json = new JSON;    $username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : '';
        $password = !empty($_POST['password']) ? trim($_POST['password']) : '';
        $captcha = !empty($_POST['captcha']) ? json_str_iconv(trim($_POST['captcha'])) : '';
        $result   = array('error' => 0, 'content' => '');    $captcha = intval($_CFG['captcha']);
        if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
        {
            if (empty($captcha))
            {
                $result['error']   = 1;
                $result['content'] = $_LANG['invalid_captcha'];
                die($json->encode($result));
            }        /* 检查验证码 */
            include_once('includes/cls_captcha.php');        $validator = new captcha();
            $validator->session_word = 'captcha_login';
            if (!$validator->check_word($_POST['captcha']))
            {            $result['error']   = 1;
                $result['content'] = $_LANG['invalid_captcha'];
                die($json->encode($result));
            }
        }    if ($user->login($username, $password))
        {
            update_user_info();  //更新用户信息
            recalculate_price(); // 重新计算购物车中的商品价格
            $smarty->assign('user_info', get_user_info());
            $ucdata = empty($user->ucdata)? "" : $user->ucdata;
            $result['ucdata'] = $ucdata;
            $result['content'] = $smarty->fetch('library/member_info.lbi');
        }
        else
        {
            $_SESSION['login_fail']++;
            if ($_SESSION['login_fail'] > 2)
            {
                $smarty->assign('enabled_captcha', 1);
                $result['html'] = $smarty->fetch('library/member_info.lbi');
            }
            $result['error']   = 1;
            $result['content'] = $_LANG['login_failure'];
        }
        die($json->encode($result));
    }
      

  3.   

    不是吧~~~
    你把 echo " <script>alert('该用户名已被人使用。');history.go(-1); </script>";
    写在 die()的后面,echo是永远都不会执行的。