PHP页面上有500错误

时间:2012-07-07 23:56:47

标签: php mysql

  

可能重复:
  Why do I keep getting a 500 error with my PHP?

我正在创建一个允许用户登录网站的页面。我一直收到500错误。这是给我一个错误的代码:

<?php

if(isset($_POST['submit']))
{
    $username = $_POST['username'];
    $password = $_POST['password'];

    include( 'connection.php' );

    if(empty($username) || empty($password))
    {
        $error = 'Please enter your username and password'
    }
    else
    {
        $password = md5($password);
        $sql = mysql_query("SELECT * FROM users WHERE username = $username AND password = $password LIMIT 1") or die(mysql_error)();
        $num_rows = mysql_num_rows($sql);

        if($num_rows == 1)
        {
            $fetch = mysql_fetch_array($sql);
            extract ($fetch);
            echo $username;
        }
        else
        {
            echo 'There was an error while logging in'
        }
    }
?>

3 个答案:

答案 0 :(得分:2)

开发期间,您可以在php.ini中设置:

  • error_reporting = E_ALL | E_STRICT
  • display_errors = On
  • display_startup_errors = On

然后在大多数情况下,您会看到错误说明而不是空白页。

如果您仍然得到空白页:

  • log_errors = On
  • error_log = php_errors.log

并且php_errors.log可能会有一些描述。

IHMO最好的想法是使用xdebug

答案 1 :(得分:1)

ifset()不是一个功能。您正在寻找isset()

答案 2 :(得分:1)

$sql = mysql_query("SELECT * FROM users WHERE username = $username AND password = $password LIMIT 1") or die(mysql_error());