-1

here is my path

main:
    Members/name.html
    search.php

Members is a folder

my html code: in name.html

    <form action="../search.php" method="get">
                            <div>
                                <br/>
                                <input type="text" name="input"  value="Search the
 site&hellip;" onfocus="this.value=(this.value=='Search the site&hellip;')? 
'' : this.value ;" />
                                <input type="submit" name="go" id="go" value="GO" />
                            </div>

but when i ran this and put something in the search bar it didn't work. i read this Using HTML form action with a php script being in another directory (relative paths) but it still doesn't work when i put the html file in the same directory as the search.php it's working great (i'm changing the path to ./search.php when it's in the same directory) but when i'm putting it back to the another directory it's not working again.

Community
  • 1
  • 1
Dkova
  • 1,087
  • 4
  • 16
  • 28
  • I'm assuming `main` is your root? If so, `/search.php` should work – Paul Dessert Mar 21 '14 at 17:59
  • Seems fine to me. Your HTML semantics are horrible but otherwise it should work. Any errors? – va5ja Mar 21 '14 at 18:02
  • Are you sure you don't have any other error? I copy-pasted your code and worked fine. Maybe you should post your code in search.php – agmezr Mar 21 '14 at 18:02
  • i have in my root index.html and there it work great with search.php i don't get any errors only this in the browser bar "...emtemplate.html?input=apple&go=GO" – Dkova Mar 21 '14 at 18:04

2 Answers2

3

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:

<form action="page.php">

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

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

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

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

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

<form action="/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']

Martijn
  • 15,791
  • 4
  • 36
  • 68
0

i found the solution to the problem:

<form action=".././search.php" method="get">

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

Dkova
  • 1,087
  • 4
  • 16
  • 28