大神 这个php代码为什么不能实现跳转,输入用户名密码后应该到expend.php的,可是却一直在原来的页面,
<html><head></head><bodybgcolor="#e211cc"><tablealign="center"border="0"><formaction=...
<html>
<head>
</head>
<body bgcolor="#e211cc" >
<table align="center" border="0">
<form action="login.php" method="post" target="_self">
用户名:<input type="text" name="username"/><br/><br/>
密 码: <input name="psd" type="password"/> <br/><br/>
<input type="submit" value="登陆"/>
</form>
</table>
<?php
if(isset($_GET['myname']))
{
echo$name=$_GET['myname'];
}
if(isset($_POST['username']))
{
$user=$_POST['username'];
$psd=$_POST['psd'];
$hostname="127.0.0.1";
$username="root";
$password="1989916";
$server_link=mysql_connect($hostname,$username,$password);
$db_link=mysql_select_db("lb_database",$server_link);
$str="select user_name from userinfo where user_id='".$user."'
and user_psw='".$psd."'";
$result=mysql_query($str,$server_link);
if($temp_array=mysql_fetch_array($result))
{
session_start();
$_SESSION['user_a']=$user;
mysql_free_result($result);
$db_close=@mysql_close($server_link);
$url="myexpend.php";
echo "<script language='javascript' type'text/javascript'>";
echo "window.location='$url'";
echo "/script";
}
else
{
mysql_free_result($result);
$db_close=@mysql_close($server_link);
echo "<script language='javascript' type='text/javascript'>";
echo "alert('用户名或密码错误,请重新输入!!')";
echo "</script>";
}
}
?>
</body>
</html> 展开
<head>
</head>
<body bgcolor="#e211cc" >
<table align="center" border="0">
<form action="login.php" method="post" target="_self">
用户名:<input type="text" name="username"/><br/><br/>
密 码: <input name="psd" type="password"/> <br/><br/>
<input type="submit" value="登陆"/>
</form>
</table>
<?php
if(isset($_GET['myname']))
{
echo$name=$_GET['myname'];
}
if(isset($_POST['username']))
{
$user=$_POST['username'];
$psd=$_POST['psd'];
$hostname="127.0.0.1";
$username="root";
$password="1989916";
$server_link=mysql_connect($hostname,$username,$password);
$db_link=mysql_select_db("lb_database",$server_link);
$str="select user_name from userinfo where user_id='".$user."'
and user_psw='".$psd."'";
$result=mysql_query($str,$server_link);
if($temp_array=mysql_fetch_array($result))
{
session_start();
$_SESSION['user_a']=$user;
mysql_free_result($result);
$db_close=@mysql_close($server_link);
$url="myexpend.php";
echo "<script language='javascript' type'text/javascript'>";
echo "window.location='$url'";
echo "/script";
}
else
{
mysql_free_result($result);
$db_close=@mysql_close($server_link);
echo "<script language='javascript' type='text/javascript'>";
echo "alert('用户名或密码错误,请重新输入!!')";
echo "</script>";
}
}
?>
</body>
</html> 展开
1个回答
2013-11-05
展开全部
把你的php代码单独拿出来,放到login.php 你 script 标签没有闭合啊!echo "/script";
这个 换成echo“</script>”;
因为我没有数据库就就弄个简单的login.php 不连数据库的,只是值判断存不存在
<?php
if(isset($_POST['username']) &&!empty($_POST['username']) && isset($_POST['psd']) && !empty($_POST['psd'])){
$url="myexpend.php";
echo "<script language='javascript' type'text/javascript'>";
echo "window.location='$url'";
echo "</script>";
}else{
echo "<script language='javascript' type='text/javascript'>";
echo "alert('用户名或密码错误,请重新输入!!')";
echo "</script>";
}
?>
这个 换成echo“</script>”;
因为我没有数据库就就弄个简单的login.php 不连数据库的,只是值判断存不存在
<?php
if(isset($_POST['username']) &&!empty($_POST['username']) && isset($_POST['psd']) && !empty($_POST['psd'])){
$url="myexpend.php";
echo "<script language='javascript' type'text/javascript'>";
echo "window.location='$url'";
echo "</script>";
}else{
echo "<script language='javascript' type='text/javascript'>";
echo "alert('用户名或密码错误,请重新输入!!')";
echo "</script>";
}
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询