<?php
session_start();
?>
<?php
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection))
{
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php'); //这行报错 }
else
{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
session_start();
?>
<?php
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection))
{
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php'); //这行报错 }
else
{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
index_bc.php路径对吗?
session_start();
?>//这里相当于有换行字符的输出了,后面header的时候当然会报错了
<?php
$db_host="127.0.0.1:3306";
改成:
<?php
session_start();
$db_host="127.0.0.1:3306";
都在同一目录下,路径没错
session_start();
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php');
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
session_start();
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.php');
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>hotel</title>
<script type="text/javascript">
function Checkform()
{if(document.form1.user_login.value=="")
{
alert("请输入用户名!");
document.form1.user_login.focus();
return false;
}
else if(document.form1.password.value == "")
{
alert("请输入密码!");
document.form1.user_pass.focus();
return false;
}
else
{
return true;
}
}</script>
</head><body>
<p> </p><form name="form1" method="post" action="" onsubmit="return Checkform();">
<table width="289" border="1" cellspacing="0" cellpadding="1" bordercolor="#999999" align="center">
<tr bgcolor="#999999">
<td>
<div align="center"><font color="#FFFFFF" size="4">用户登录</font></div>
</td>
</tr>
<tr>
<td>
<table width="267" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td width="94">
<div align="right">用户:</div>
</td>
<td width="169">
<input type="text" name="user_login" size="16" maxlength="16" >
</td>
</tr>
<tr>
<td width="94">
<div align="right">密码:</div>
</td>
<td width="169">
<input type="password" name="user_pass" size="16" maxlength="16">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="login" value=" 登 录 ">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form></body>
</html>
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404
127.0.0.1
08/10/10 17:05:33
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.htm');
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
大侠们帮帮忙吧,我加分
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\APMServ5.2.6\www\htdocs\KJ\in.php:2) in D:\APMServ5.2.6\www\htdocs\KJ\in.php on line 3Warning: Cannot modify header information - headers already sent by (output started at D:\APMServ5.2.6\www\htdocs\KJ\in.php:2) in D:\APMServ5.2.6\www\htdocs\KJ\in.php on line 18<?php
session_start();//这行报错
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.htm');//这行报错
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
且文件保存的编码是utf-8的话,也不能保存bom头
session_start();
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
if($res=mysql_query($query,$connection)){
$_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.htm');
}else{
echo "<script>alert('用户名或密码不正确');</script>";
}
?>
我这样改完,页面直接进入index_bc.htm了,我的登录页没有进入啊
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
$res=mysql_query($query,$connection);
if(mysql_fetch_array($res)){
报错
if(isset($_SESSION["user_id"]))unset($_SESSION["user_id"]);或:isset($_SESSION["user_id"]) && $_SESSION["user_id"]="";
session_start();
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
$res=mysql_query($query,$connection);
if(mysql_fetch_array($res)){ $_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('location:index_bc.htm');exit;
}else{
echo "<script>alert('登录成功');</script>";
}
?>
这样写登录正常,但是打开页面时,先后弹出2个提示框,一个是乱码提示框,一个是登录成功提示框。
<?php
session_start();
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="hotel";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("选择服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
mysql_query("set names 'utf8'");$user_login=$_POST["user_login"];
$user_pass=$_POST["user_pass"];
$query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
$res=mysql_query($query,$connection);
if(mysql_fetch_array($res)){ $_SESSION['user_login']=$user_login;
$_SESSION['user_pass']=$user_pass;
header('Location:index_bc.htm');exit;
}else{
echo "<script>alert('登录成功');</script>";
}
?>