Using HTML form action with a php script being in another directory (relative paths)

后端 未结 4 1965
甜味超标
甜味超标 2021-01-04 12:43

Here\'s what my diretory tree looks like

/application
    /lib
    /util
        /login
    /views
        /base_view

My login page is

相关标签:
4条回答
  • 2021-01-04 13:14

    I faced the a similar problem and the error I got was object not found /application /includes connect.php insert.php index.php

    <form action="/includes/insert.php" method="post">
        //code
    </form>
    

    the above code didn't work and showed the error 404, Object Not Found. But,

    <form action="./includes/insert.php" method="post">
        //code
    </form>
    

    The only difference is adding . in the action path. The strange things is /include/filename works fine for require or include but you will need to add . for form action attribute

    0 讨论(0)
  • 2021-01-04 13:18

    In your relative path ./util/login/main.php, you're using ./ which refers to the current folder, so it assumes that the folder structure /util/login is inside /base_view. You should try using ../ which refers to the parent folder:

    <form class="form_login" action="../../util/login/main.php" method="POST">
    ...
    </form>
    
    0 讨论(0)
  • 2021-01-04 13:35

    You must use .. / to go to parent directory

    <form class="form_login" action="../../util/login/main.php" method="POST">
    ...
    </form>
    
    0 讨论(0)
  • 2021-01-04 13:36

    You need to set the action to a better relative path or use an absolute path. Examples:

    ../../util/login/main.php
    

    or

    /astuto-lena/branches/application/util/login/main.php
    

    ./ simply means this directory (aka current working directory)

    0 讨论(0)
提交回复
热议问题