<?php
$bt="修改用户名";
include("../conn.php");
include("../head.php");
include_once("../function.php");
$sid = sqlstr($_COOKIE['dl']);
$uin=mysql_fetch_array(mysql_query("select * from user where sid='$sid'"));
$id=$uin["id"];
if(!$uin){
header("Location:../login.php");
exit;//没登录就跳转到登录页面
}
$action=sqlstr($_GET["action"]);
$username=sqlstr($_POST["name"]);
if($action==post){

if($username!=Null){
if(mysql_fetch_array(mysql_query("SELECT * FROM user  WHERE name='$username'"))){$txt="<font color='red'>你填写的用户名已经被其他人用了啦</font>";
}elseif(mb_strlen($username,'utf-8') < 2 or mb_strlen($username,'utf-8')> 10){$txt="<font color='red'>用户名长度应在2~10个字之间</font>";
}else{
mysql_query("UPDATE user SET name='$username' WHERE id='$id'");
$txt="<font color='red'>用户名修改成功，以后请用此用户名登录</font>";
}
}else{
$txt="<font color='red'>请输入你要修改的用户名</font>";
}

}

?>
<div id="main">
<?php echo $txt; ?>
<form action="name.php?action=post" method="POST">
<br/>输入新用户名(10字内)：<br/>
<p> <input type="text"  class="loginput" name="name" maxlength="20"/> </p>
<input class="libbtn" type="submit" value="修改" />　　<a href="/m/user/setting.php">返回>></a></form>
</div><br/>

<?php include("../footer.php"); ?>