当我使用这段 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 有问题?
最佳答案
存在以下问题:-
您的第一个 if 括号未关闭。所以关闭了它。
您的表单方法不正确。拼写错误:-
所以正确的代码在这里:-
<?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/