php - 运行 php 文件时如何修复“404 page not found”错误?
问题描述
我刚刚开始学习 php,当我运行我的 php 文件时,无论使用哪种浏览器,我都会收到 404 错误。我的代码缺少什么导致这种情况?该文件应该在用户提交“联系我”表单后显示一条消息。
<!DOCTYPE html>
<html lang="">
<head>
<title>Contact Form Submitted</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<p>
Thank you, <?php echo $_POST["name"]; ?> for your comments<br>
You stated in your test Message:<br>
<?php echo $_POST["message"]; ?>
We will respond to you at <?php echo $_POST["email"]; ?> when we make updates to the site.
</p>
</body>
</html>
解决方案
此代码有效。看到这是火狐:https ://i.imgur.com/YeBFt9B.png
<?php
// var // variable value // default value
$php_path = $_SERVER['PHP_SELF'] ?? "";
$name = $_POST["name"] ?? "name";
$message = $_POST["message"] ?? "message";
$email = $_POST["email"] ?? "email";
?>
<!DOCTYPE html>
<html lang="">
<head>
<title>Contact Form Submitted</title>
</head>
<body>
<form action="<?= $php_path ?>" method="POST">
<p>
Thank you, <?= $name ?> for your comments<br>
You stated in your test Message:<br>
<?= $message ?>
<br><br>
We will respond to you at <?= $email ?> when we make updates to the site.
</p>
</form>
</body>
</html>
如果您没有在其他表单的参数上指定默认值,您可能会遇到意外错误。这个版本更好;)
我确定您收到此错误是因为您的某个网址中有错字
推荐阅读
- javascript - 删除促销代码后最终金额不变
- php - PHP替换文件扩展名不会加载
- quicksort - 你能解释一下为什么随机快速排序的预期运行时间是 nlogn 的 Theta 吗?
- excel - 可调整范围的工作表函数计数
- azure-active-directory - 不能创建超过 1 个组生命周期策略
- oracle - 使用 plsql 的第一列更新两列中的数据
- php - Zend 3 直接 Sql 查询执行
- javascript - 检查任何新的经纬度是否在 100 米范围内?从我现在的位置
- iphone - 未知类型名称“NS_ASSUME_NONNULL_BEGIN”
- css - 如何动态更改 CSS 光标 vuejs