Skip to content Skip to sidebar Skip to footer

Using Html Form Action With A Php Script Being In Another Directory

here is my path main: Members/name.html search.php Members is a folder my html code: in name.html

Solution 1:

There are multiple ways. Let's assume you are at domein.ext /dir1/dir2/

If you want to post to the exact current url (if you have nice urls, this occurs):

<form><!-- No target, only in HTML5 -->

If you have page.php in the same dir:

<formaction="page.php">

If you are in dir2, and want a file from dir1 (so up 1 dir):

<formaction="../page.php"><!-- ../ means 'up one dir' -->

If you are in dir1, and need something in dir2:

<formaction="./dir2/page.php"><!-- ./ means 'current dir' -->

If you want the location to the resource to be checked from the domain, you start with slash:

<formaction="/whole/different/dirs/page.php"><!-- / means 'document root' -->

Handy to know, ./ and ../ are very common, they work in php includes, resources in webpages, commandline, etc etc. Please note, the / in php doesnt mean 'document root', in php it will link to /home (on a LINUX server). Thats why you have $_SERVER['DOCUMENT_ROOT']

Solution 2:

i found the solution to the problem:

<formaction=".././search.php"method="get">

i use ../ to go back in folders like "martijn" said and ./ for the php use

Post a Comment for "Using Html Form Action With A Php Script Being In Another Directory"