简体   繁体   English

在另一个目录中使用HTML表单动作和php脚本

[英]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 我的html代码:在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. 我阅读了使用HTML表单操作并将php脚本放在另一个目录(相对路径)中的方法,但是当我将html文件放在与search.php相同的目录中时,它仍然无法正常工作(我正在更改./search.php路径(在同一目录中),但是当我将其放回另一个目录时,它不再起作用。

There are multiple ways. 有多种方法。 Let's assume you are at domein.ext /dir1/dir2/ 假设您位于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: 如果您在同一目录中有page.php

<form action="page.php">

If you are in dir2, and want a file from dir1 (so up 1 dir): 如果您在dir2中,并且想要dir1中的文件(因此1个dir):

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

If you are in dir1, and need something in dir2: 如果您在dir1中,并且在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. 容易知道的./../非常常见,它们在php include,网页资源,命令行等中工作。
Please note, the / in php doesnt mean 'document root', in php it will link to /home (on a LINUX server). 请注意,PHP中的/并不表示“文档根目录”,在php中它将链接至/home (在LINUX服务器上)。 Thats why you have $_SERVER['DOCUMENT_ROOT'] 这就是为什么您有$_SERVER['DOCUMENT_ROOT']

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 我用../返回到像“ martijn”这样的文件夹中,而./用于php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM