HTML代码:
<form action="./php/login.php" name="loginform" accept-charset="utf-8" id="login_form" class="loginForm" method="post">
<input type="hidden" name="did" value="0"/>
<input type="hidden" name="to" value="log"/>
<div class="uinArea" id="uinArea">
<label class="input-tips" for="u">手机号:</label>
<div class="inputOuter" id="uArea">
<input type="text" name="phone" class="inputstyle"/>
</div>
</div>
<div class="pwdArea" id="pwdArea">
<label class="input-tips" for="password">密码:</label>
<div class="inputOuter" id="pArea">
<input type="password" name="password" class="inputstyle"/>
</div>
</div>
<div style="padding-left:75px;margin-top:20px;">
<input type="submit" value="登 录" style="width:150px;" class="button_blue"/>
</div>
</form>
PHP代码:
<?PHP
header("Content-Type: text/html; charset=utf-8");
include('conn.php');//链接数据库
$phone = $_POST['phone'];//post获得用户名表单值
$password = $_POST['password'];//post获得用户密码单值
if ($phone && $password){//如果用户名和密码都不为空
$sql = "select * from user where phone = '$phone' and password = '$password' ";//检测数据库是否有对应的tel和password的sql
$res = mysql_query($sql);//执行sql
$rows = mysql_num_rows($res);//返回一个数值
if($rows){//0 false 1 true
header("refresh:0;url=../index.html");//如果成功跳转至index.html页面
exit;
}else{
echo "手机号或密码错误";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
}
}else{//如果手机号或密码有空
echo "没有获取到手机号或者密码";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试,让其从新进行输入
}
mysql_close();//关闭数据库
?>
这是登录的html和php,用手机号码作为账号进行登录,可以正常登录,想在登录后跳转的index.html页面的右上角显示登录用户的昵称,就是对应的user_name,通过phone查询表获取这个user_name,这样可以吗?该怎么写?然后html怎么输出出来?