php - 使用 MAMP 进行文件路由

标签 php html mysql

我一直在从一本名为“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/

相关文章:

php - 如何在我的 Android 应用程序中使用全局变量从 mysql 检索用户的登录 ID?

javascript - 更改时更新 PHP session 变量

javascript - 我想根据 java 脚本值显示 css 通知

php - 不同的选择不能正常工作

php - 搜索键分页问题,​​当单击任何链接或搜索另一个键时,应该使用 unset 来销毁 session

php - 将表单值提交到数据库、php

php - 简单的 jQuery AJAX 文件上传

javascript - 检查滚动条是否到达了带有jquery的div

html - 当表格设置为 100% 宽度时锁定 html 表格标题

javascript - 使用 POST 的 NodeJS 快速身份验证返回错误 发送后无法设置 header