用于转换表单中的文本以进行查询的脚本?
我是一个新手,想从 php 开始。我已经了解一些 javascript 了。
我希望能够在表单中输入一些文本并将其转换为查询,例如 在我的网站中有一个搜索框,我输入“example”,然后单击“提交”,它给了我这个=
http://www.externalsite.com/search?s=example&x=0 并将其粘贴到地址栏,就像搜索引擎一样。
任何指导将不胜感激。
I'm a total newbie and want to start with php. I know some javascript already.
I want to be able to type some text in a form and convert it to a query e.g.
In my website there's this search box, I type in 'example' click submit and it gives me this=
http://www.externalsite.com/search?s=example&x=0
and pastes it to the address bar, you know like a search engine.
Any guidance will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,当您使用 PHP 时,您应该将表单指向提交到 PHP 文件。然后要检索数据,请使用 $_GET 或 $_POST ,具体取决于您的表单是发布还是获取(正如我从您的示例中看到的,它是 GET),如下所示:
HTML :
在 PHP 方面:
Well, as you are doing PHP, you should point your form to submit to a PHP file. Then to retrieve the data, use $_GET or $_POST depending your form is posting or getting (as I can see from your exemple its a GET) so something like this :
HTML :
On the PHP side :
基本上,您将搜索词输入到表单中,然后将其发布(通过 GET)到搜索页面,该页面在其数据库中查询与该字符串匹配的记录。一个简单的示例如下:
index.php
当您提交该文件时,它会将您引导至
search.php?terms=[terms here]
。我们在 search.php 中找到的代码如下:search.php
这是一个非常简单的示例(不要将其复制/粘贴到生产中)。本质上,您将提交的值提取到查询中,然后显示任何结果。这应该足以帮助您入门,但如果您将来有更具体的问题,请随时访问我们。
祝你好运!
Basically you're typing your search term into a form, which then posts (via GET) to a search page, which queries its database for records matching that string. A simple example of this follows:
index.php
When you submit that, it will direct you to
search.php?terms=[terms here]
. Our code found within search.php follows:search.php
This is a very simple example (don't copy/paste this into production). Essentially you're pulling the submitted value(s) into a query, and then showing any results. This should be enough to get you started, but feel free to visit us here if/when you have more specific questions in the future.
Best of luck!