duanhunlou7051 2013-03-06 21:26
浏览 7

too long

This question already has an answer here:

I am still getting that error when I run my code. Here is my code.I removed all white spaces as well.my form on my html goes to my php (action="lib/login.php") file to check if user exists. If it exist, then redirect. dbconnect.php just connects to my database. can anyone help?

FOLDER Layout:
lib
-dbconnect.php
-login.php (code located below)
index.html

<?php
 require_once("dbconnect.php"); 

 $loginuser = $_POST['username'];
 $loginpw = $_POST['password']; 
 $usertable = "Users";
 $users="Username";
 $pw="Password";
 $query = "SELECT $users, $pw FROM $usertable WHERE $users='$loginuser' AND $pw='$loginpw'";           
 $result = mysql_query($query);
 $num_rows = mysql_num_rows($result);                                  
 if (!$result) {
    die('Invalid query: ' . mysql_error());
}

 if ($num_rows>0) {
    header("Location:../index.html");
    exit();       
}                                      

?>

</div>
  • 写回答

1条回答 默认 最新

  • dousi4950 2013-03-06 21:33
    关注

    This message appears if you try to send a HTTP header after you already made some output. This is because in HTTP there comes first the headers and then the body. As ouput goes to the body, it is impossible to send headers anymore after output.

    As there is no echo, print or whatever output function used in your code, output can be generated by

    1. A PHP errror message
    2. Content before the opening <?php

    To 1:

    The ob_* set of functions is a good way to catch all output a script regardless if this are error messages or regular output. So you could add the line:

    ob_start();
    

    direct after the opening <?php tag.

    Then before the call to header() add:

    if(ob_get_size() > 0) {
        // there was an error, display it and exit
        ob_end_flush();
        die();
    }
    

    Note that in production environment you should disable the display of error messages at all as they can contain sensitive information. You can do by settings display_errors in php.ini to 0 or per script by:

    ini_set('display_errors', 0);
    

    To 2:

    Assuming that the code you have posted is the complete content of the php file (no spaces or empty lines before <?php ) it could be that you have a problem with the UTF-8 BOM char. BOM means byte order mark and is used internally by the utf-8 encoding. And it is not visible in a text editor. :)

    To remove it, there are several solutions out there.. will google one for you ..... http://www.w3.org/International/questions/qa-byte-order-mark.en.php

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?