PHP 生成一个空白网页

标签 php html

当我使用这段 PHP 时,它会使网页空白(白色)并且不显示任何内容。这是我的代码:

<?php
if(isset($_POST['submit'])){
//
$user = $_POST['username'];
$pwrd = $_POST['pwrd'];
//include database connection
include('../includes/db_connect.php');
if(empty($user) || empty($pwrd)){
    echo 'Missing information';
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div id="container">
<form action="Login.php" mthod="post">
    <p>
    <label>Username</label><input type="text" name="username" />
    </p>
    <p>
    <label>Password</label><input type="password" name="pwrd" />    
    </p>
    <input type="submit" name="submit" value="logIn" />
</form>

</div>
</body>
</html>


在测试了 PHP 代码的不同部分后,我注意到只有这段代码使页面空白

if(empty($user) || empty($pwrd)){
    echo 'Missing information';
}
?>

这可能与 Apache 有关,还是我的 PHP 有问题?

最佳答案

存在以下问题:-

  1. 您的第一个 if 括号未关闭。所以关闭了它。

  2. 您的表单方法不正确。拼写错误:-

所以正确的代码在这里:-

<?php
if(isset($_POST['submit'])){
    //
    $user = $_POST['username'];
    $pwrd = $_POST['pwrd'];
    //include database connection
    include('../includes/db_connect.php');
    if(empty($user) || empty($pwrd)){
        echo 'Missing information';
    }
}// missing
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div id="container">
<form action="Login.php" method="post"> // method is written mthod
    <p>
    <label>Username</label><input type="text" name="username" />
    </p>
    <p>
    <label>Password</label><input type="password" name="pwrd" />    
    </p>
    <input type="submit" name="submit" value="logIn" />
</form>

</div>
</body>
</html>

输出:- 提交前:- http://prntscr.com/74xhb7 提交后:- http://prntscr.com/74xhmm

注意:- 我让你关闭的括号你可以根据你的方便程度关闭它。谢谢。

也不要因第二个屏幕截图中看到的错误而 panic 。这是因为我最后没有包含文件。

关于PHP 生成一个空白网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30226455/

相关文章:

PHP - 将 <head></head> 数据作为包含加载是否愚蠢

html - 如何在 HTML 和 CSS 中使 block 元素居中?

html - css:50% 宽度 div 之间的 20px 间距

html - 当 "justify-content"设置为 "space-between"时,如何左对齐最后一个 flex 元素?

php - 如何将 laravel 5.3 项目放在共享主机上

php - 从数据库获取数据的函数

javascript - 1次点击打开2个链接

javascript - 全日历星期几三位数

基于 PHP MySQL 的近似匹配搜索

javascript - 如何加快网页加载时间(CRON?在后台加载 API 调用?)