我一直在从一本名为“PHP 和 MySQL - Web 开发”的书中自学 php,并通过其中提供的示例进行练习。它要求您使用 html 制作一个简单的订单表格,并创建一个名为“processorder.php”的 php 文件,该文件应该在提交订单表格时出现。下面是表单页面的代码:
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Place an Order</title>
</head>
<body>
<form action = "/Applications/MAMP/htdocs/processorder.php"
method="post">
<table style = "border: opx;">
<tr style = "background: #cccccc;">
<td style = "width: 150px; text-align: center;">Item</td>
<td style = "width: 15px; text-align:
center;">Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td><input type = "text" name = "tireqty" size = "3"
maxlength = "3" /></td>
</tr>
<tr>
<td>Oil</td>
<td><input type = "text" name = "oilqty" size = "3" maxlength = "3" /></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td><input type = "text" name = "sparkqty" size = "3"
maxlength = "3" /></td>
</tr>
<tr>
<td colspan = "2" style = "text-align: center;"><input
type = "submit" value = "Submit Order" /></td>
</tr>
</table>
</form>
</body>
</html>
这是 php:
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
echo '<p>Order processed.</p>';
?>
</body>
</html>
我已确保将 php 文件放在正确的目录中,但是当我使用 MAMP 运行所有这些文件时,我收到一条错误消息“未找到请求的 URL/Applications/MAMP/htdocs/processorder.php这个服务器。”任何帮助将不胜感激。我是 php 新手,欢迎任何建议。
最佳答案
Apache 将根据其 Web 根自动提取文件。在您的情况下,apache 指向 /Applications/MAMP/htdocs
。因此,您提供的所有文件路径都应该相对于该目录,允许您仅使用 /processorder.php
。
值得注意的是,如果你有一个前导斜杠 /
它将相对于 webroot,如果没有,它将相对于当前目录。例如,如果您位于 /hello/world.php
并将操作设置为 processorder.php
,它将提交到 /hello/processorder.php
关于php - 使用 MAMP 进行文件路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44509270/