12

Here's what my diretory tree looks like

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

My login page is

localhost:737/astuto-lena/branches/application/views/base_view/index.php

And I want the action of my form to be this

localhost:737/astuto-lena/branches/application/util/login/main.php

Here's my form declaration

<form class="form_login" action="./util/login/main.php" method="POST">
...
</form>

But when I click the submit button, it takes me to

localhost:737/astuto-lena/branches/application/views/base_view/util/login/main.php

Which is the wrong path and generates a Error 404.

So what's wrong with the way I'm using relative paths in my form declaration and how can I fix that?

Flayshon
  • 363
  • 1
  • 5
  • 12

4 Answers4

11

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>
DarkAjax
  • 15,955
  • 11
  • 53
  • 65
  • Thanks! Just to clarify: is there any reason why I should use the `../` twice? Or maybe a situation where I could use just one `../` ? – Flayshon Jun 06 '13 at 22:41
  • 3
    @Flayshon actually Yes there is a difference, basically in your case, you start in `localhost:737/astuto-lena/branches/application/views/base_view/`, if you use `../` once you'll end up in `localhost:737/astuto-lena/branches/application/views/` and using it twice will get you to `localhost:737/astuto-lena/branches/application/` which is also the folder that contains `/util/login/` – DarkAjax Jun 06 '13 at 23:57
2

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)

Rob W
  • 9,134
  • 1
  • 30
  • 50
1

You must use .. / to go to parent directory

<form class="form_login" action="../../util/login/main.php" method="POST">
...
</form>
Luferquisa
  • 73
  • 7
0

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