首页 > 代码库 > dedecms--后台添加会员栏目(批量添加)
dedecms--后台添加会员栏目(批量添加)
最近在用dedecms二次开发会员功能,一开始做了一个会员添加,但是领导要求可以批量添加,最好是可以输入添加个数;这样我想添加几个就添加几个了
1:会员添加的htm页面
<html>
<head>
<meta charset="utf-8">
<title>添加会员</title> <link href=http://www.mamicode.com/‘img/base.css‘ rel=‘stylesheet‘ type=‘text/css‘>
<script language=‘javascript‘ src=http://www.mamicode.com/‘../data/enums/area.js‘></script>
</head>
<body leftmargin=‘8‘ topmargin=‘8‘>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#D1DDAA">
<tr>
<td height="19" background="img/tbg.gif"><a href=http://www.mamicode.com/‘<?php echo $ENV_GOBACK_URL; ?>‘>
<b>会员管理 </b></a> 添加会员
</td>
</tr>
<tr>
<td height="200" bgcolor="#FFFFFF" align=‘center‘>
<table width="98%" border="0" cellspacing="0" cellpadding="6" >
<tr> <td colspan="2" height="10" >
</td>
</tr>
<form name="form2" action="member_add.php" method="post">
<input type="hidden" name="dopost" value="http://www.mamicode.com/add" />
<tr>
<td width="17%" align="right" class=‘bline‘>用户名</td>
<td width="83%" class=‘bline‘>
<input name="userid" type="text" value="" id="userid" size="20" style="width:150px;height:20px" /> </td>
</tr>
<tr>
<td align="right" class=‘bline‘>用户密码</td>
<td class=‘bline‘> <input type="password" name="pwd" id="pwd" style="width:150px;height:20px"/> </td>
</tr>
<tr>
<tr>
<td align="right" class=‘bline‘>添加个数</td>
<td class=‘bline‘> <input type="text" name="num" id="num" style="width:150px;height:20px"/> </td>
</tr>
<tr>
<tr> <td align="right" class=‘bline‘>有效时间</td> <td class=‘bline‘>
<input type="radio" name="exptime" class="np" value="http://www.mamicode.com/30" /> 一个月
<input type="radio" name="exptime" class="np" value="http://www.mamicode.com/7" checked=‘1‘/> 一周
<input type="radio" name="exptime" class="np" value="http://www.mamicode.com/1" /> 一天 </td>
</tr>
<tr>
<td height="67" align="right" ></td> <td height="67" >
<input type="submit" name="Submit" value="http://www.mamicode.com/确定添加" class=‘coolbg‘ />
<input type="reset" name="Submit22" value="http://www.mamicode.com/重置表单" class=‘coolbg‘ /> </td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
2:member_add.php(批量添加的时候主要做的是循环,将随机生成的用户登录和用户密码放数据里面,然后再循环两个数组,挨个将用户名和密码存入数据库中)
<?php
require(dirname(__FILE__)."/config.php");
$ENV_GOBACK_URL = isset($_COOKIE[‘ENV_GOBACK_URL‘]) ? "member_main.php" : ‘‘;
if($dopost=="add"){
$jointime = $logintime = time();
$loginip = $joinip = GetIP();
$userid=mb_convert_encoding($userid,‘GBK‘, ‘utf-8‘);
$pwd=$pwd;
if(!$userid && !$pwd){
if(!$num){$num=1;}
for($i=0;$i<$num;$i++){
$string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
for($j=0;$j<5;$j++){
$userid[$i].= $string[rand(0,strlen($string)-1)];
}
for($k=0;$k<6;$k++){
$pwd[$i].= $string[rand(0,strlen($string)-1)];
}
}
for($m=0;$m<$num;$m++){
//检测用户名是否存在
$username=$userid[$m];
$row = $dsql->GetOne("SELECT mid FROM `#@__member` WHERE userid=‘$username‘ ");
if(is_array($row))
{
ShowMsg("你指定的用户名 {$username} 已存在,请使用别的用户名!", "-1");
exit();
}
$password= $pwd[$m];
$mpwd = md5($pwd[$m]);
echo "<table><tr><td>用户名:".$username."</td><td>用户密码:".$password."</td></tr></table>";
$dsql->ExecuteNoneQuery("INSERT INTO dede_member SET `mtype`=‘$mtype‘,`userid`=‘$username‘,`pwd`=‘$mpwd‘,`password`=‘$password‘,`uname`=‘$uname‘,`sex`=‘$sex‘ ,`rank`=‘$rank‘,`exptime`=‘$exptime‘,`money`=‘$dfmoney‘, `email`=‘$email‘, `scores`=‘$dfscores‘, `matt`=‘0‘, `face`=‘‘,`safequestion`=‘0‘,`safeanswer`=‘$safeanswer‘, `jointime`=‘$jointime‘,`joinip`=‘$joinip‘,`logintime`=‘$logintime‘,`loginip`=‘$loginip‘;");
}
ShowMsg(‘会员帐号批量添加成功‘);
}else{
//检测用户名是否存在
$row = $dsql->GetOne("SELECT mid FROM `#@__member` WHERE userid LIKE ‘$userid‘ ");
if(is_array($row))
{
ShowMsg("你指定的用户名 {$userid} 已存在,请使用别的用户名!", "-1");
exit();
}
$mpwd = md5($pwd);
echo "<table><tr><td>用户名:".$userid."</td><td>用户密码:".$pwd."</td></tr></table>";
$dsql->ExecuteNoneQuery("INSERT INTO dede_member SET `mtype`=‘$mtype‘,`userid`=‘$userid‘,`pwd`=‘$mpwd‘,`password`=‘$pwd‘,`uname`=‘$uname‘,`sex`=‘$sex‘ ,`rank`=‘$rank‘,`exptime`=‘$exptime‘,`money`=‘$dfmoney‘, `email`=‘$email‘, `scores`=‘$dfscores‘, `matt`=‘0‘, `face`=‘‘,`safequestion`=‘0‘,`safeanswer`=‘$safeanswer‘, `jointime`=‘$jointime‘,`joinip`=‘$joinip‘,`logintime`=‘$logintime‘,`loginip`=‘$loginip‘;");
ShowMsg(‘成功添加一个会员帐号‘);
}
exit();
}else{
include DedeInclude(‘templets/member_add.htm‘);
}
?>
dedecms--后台添加会员栏目(批量添加)