【问题标题】:PHP line of code is not working with html form! 500 ERRORPHP 代码行不适用于 html 表单! 500 错误
【发布时间】:2014-04-18 16:40:42
【问题描述】:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
    <title>MechRook</title>
    <link type="text/css" rel="stylesheet" href="css.css"/>
    <link type="image/jpeg" rel="short icon" href="favicon.jpg"/>
</head>
<body>
    <div id="fheader">
        <h1>Account</br></h1>
        <?php
        $form = '<form method="post" action="index.php">
            Username: <input name="user" type="text"></br>
            Password: <input name="pass" type="password"></br>
            <input name="btn" type="submit" value="Login">
        </form>';
        if ($_POST['btn']) {
            $user = $_POST['user'];
            $pass = $_POST['pass'];

            if ($user) {
                if($pass) {
                    echo "$user - $pass <hr> $form";
                }
                else {
                    echo "You must enter your password. $form";
            }
            else {
                echo "You must enter your username. $form";
            }   
        }
        else {
            echo $form;
        }
        ?>
        <h2>Account:</br><?php echo $_POST['user']; ?></h2>
    </div>
    <div id="sheader">
        <h1 style="font-size:50px">MechRook</h1>
        <section id="con">
            <div class="button">
                <a href="index.html" class="link">Home</a>
            </div>
            <div class="button">
                <a href="account.html" class="link" style="font-size:15px">Account</a>
            </div>
            <div class="button">
                <a href="contact.html" class="link">Contact</a>
            </div>
        </section>
        <h2>
            </br></br>Welcome to MechRook
        </h2>
        <p>
            Welcome to MechRook! MechRook is currently nothing. Wow what a waste of a URl, you might think that but you will see. My friends and I have big plans for MechRook. We have multiple designers for website templates and coders.
        </p>
    </div>
</body>
</html>

它给了我一个 500 错误。我正在尝试制作表格!请帮忙!告诉我我能做什么。谢谢!________________________________________________________________________________________________________________

【问题讨论】:

  • 1. Enable error reporting 看看它是否改变了什么。 2. 检查您的服务器日志。
  • 在此语句后缺少右大括号 (}):echo "You must enter your username. $form";
  • 等待我认为我修复了它,但它仍然给我一个错误:Internal Server Error 服务器遇到内部错误或配置错误,无法完成您的请求。请联系服务器管理员以告知错误发生的时间以及您可能所做的任何可能导致错误的事情。服务器错误日志中可能提供有关此错误的更多信息。 mechrook.com 上的 Web 服务器

标签: php html database forms


【解决方案1】:

我不是 PHP 程序员(我做 JS,而且我对它比较陌生),但是我马上发现你缺少一个右括号。该页面将显示以下代码:

if ($_POST['btn']) {
        $user = $_POST['user'];
        $pass = $_POST['pass'];

        if ($user) {
            if($pass) {
                echo "$user - $pass <hr> $form";
            } else {
                echo "You must enter your password. $form";
            }
        } else {
            echo "You must enter your username. $form";
        }   
    } else {
        echo $form;
    }

【讨论】:

  • 什么不起作用?这是添加了右括号的代码:jsfiddle.net/y67Z5 您是否在可以解释 PHP 的服务器上进行测试?
【解决方案2】:

我在添加缺少的括号后在服务器上进行了测试,它工作正常,所以只需尝试这个新代码(它没有混乱的 if-else 条件):

<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
    <title>MechRook</title>
    <link type="text/css" rel="stylesheet" href="css.css"/>
    <link type="image/jpeg" rel="short icon" href="favicon.jpg"/>
</head>
<body>
    <div id="fheader">
        <h1>Account</br></h1>
        <?php
        $form = '<form method="post" action="'.$_SERVER['PHP_SELF'].'">
            Username: <input name="user" type="text"></br>
            Password: <input name="pass" type="password"></br>
            <input name="btn" type="submit" value="Login">
        </form>';
        if ($_POST['btn']) {
            $user = $_POST['user'];
            $pass = $_POST['pass'];

            if (($user) && !($pass)) {
                echo "You must enter your password. $form";
            }
            else if (!($user) && ($pass)) {
                echo "You must enter your username. $form";
            }
            else if (!($user) && !($pass)){
                echo "You must enter your username and your password. $form";
            }
            else {
                echo "$user - $pass <hr> $form";
            }

        }
        else {
            echo $form;
        }
        ?>
        <h2>Account:</br><?php echo $_POST['user']; ?></h2>
    </div>
    <div id="sheader">
        <h1 style="font-size:50px">MechRook</h1>
        <section id="con">
            <div class="button">
                <a href="index.html" class="link">Home</a>
            </div>
            <div class="button">
                <a href="account.html" class="link" style="font-size:15px">Account</a>
            </div>
            <div class="button">
                <a href="contact.html" class="link">Contact</a>
            </div>
        </section>
        <h2>
            </br></br>Welcome to MechRook
        </h2>
        <p>
            Welcome to MechRook! MechRook is currently nothing. Wow what a waste of a URl, you might think that but you will see. My friends and I have big plans for MechRook. We have multiple designers for website templates and coders.
        </p>
    </div>
</body>
</html>

希望它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多