<?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>";
}
?>

解决方案 »

  1.   

    什么错误?
    index_bc.php路径对吗?
      

  2.   

    <?php
    session_start();
    ?>//这里相当于有换行字符的输出了,后面header的时候当然会报错了
     <?php
    $db_host="127.0.0.1:3306";
    改成:
    <?php
    session_start();
    $db_host="127.0.0.1:3306";
      

  3.   

    Warning: Cannot modify header information - headers already sent by (output started at D:\APMServ5.2.6\www\htdocs\KJ\Untitled-3.php:4) in D:\APMServ5.2.6\www\htdocs\KJ\Untitled-3.php on line 19
    都在同一目录下,路径没错
      

  4.   

    <?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("选择数据库失败");$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>";
    }
    ?>
      

  5.   

    <?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.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>
      

  6.   

    直接就
    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 
      

  7.   

    我的意思是,,确认文件保存,不要有bom头
      

  8.   

    是我的文件名写错了,应该是.htm,但我这样改完,页面直接进入index_bc.htm了,我的登录页没有进入啊
    $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>";
    }
      

  9.   

    当我把数据库中的用户名和密码信息删除后又报错
    大侠们帮帮忙吧,我加分
    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>";
    }
    ?>
      

  10.   

    文件开始的<?php必须在第一行。
    且文件保存的编码是utf-8的话,也不能保存bom头
      

  11.   

    <?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>";
    }
    ?>
    我这样改完,页面直接进入index_bc.htm了,我的登录页没有进入啊
      

  12.   

    if($res=mysql_query($query,$connection)){//你这里即使没有数据都是成立的应该是:
    $query="select * from Background where user='".$user_login."' and pwd='".$user_pass."'";
    $res=mysql_query($query,$connection);
    if(mysql_fetch_array($res)){
      

  13.   

    isset($_SESSION["user_id"]) && unset($_SESSION["user_id"]);
    报错
      

  14.   

    那就改成:
    if(isset($_SESSION["user_id"]))unset($_SESSION["user_id"]);或:isset($_SESSION["user_id"]) && $_SESSION["user_id"]="";
      

  15.   

    <?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>";
    }
    ?>
    这样写登录正常,但是打开页面时,先后弹出2个提示框,一个是乱码提示框,一个是登录成功提示框。
      

  16.   

     header('location:index_bc.php');  其中location的l应该大写如: header('Location:index_bc.php'); 
      

  17.   

    打开页面先弹出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>";
    }
    ?>