Table of Contents
拜天拜地 :{ 在线等
Jun 23, 2016 pm 02:00 PM
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <style type = "text/css"> #outer{position:absolute; left:500px; top:300px; } </style> </head> <body > <div id = "outer"><form action = "127.0.0.1/formSearch.php" method = "post"><label for = "searchItem">Search Books:</label><input type = "text" name = "searchItem" id = "searchItem" size = "50" maxlength = "500" /><input type = "submit" value = "Search" /></form></div> </body></html>
Copy after login
#实现一个简单的搜索框,然后通过127.0.0.1连接本地的apache服务,window平台,root_doc,是E:/CodeEdit/php,下面是php解析脚本:
<html><body><head><title>search result</title></head><script language = "php">$item = trim($_POST['searchItem']) ;if (!isset($item)){ echo "<p>what you want to search..</p>"; //$item = "javascript";}if (!get_magic_quotes_gpc()){ $item = addslashes($item);}$db = new mysqli("localhost", "root", "cai123",'phpdb');if (mysqli_connect_errno()){ echo "<p>can not to connect to database</p>";}$query = "SELECT * FROM books WHERE bookname LIKE"."'%".$item."%'";$result = $db->query($query);if (!$result){ echo "<p>no record was found...</p>";}$items = $result->fetch_object();echo "<ul><li>ISBN: ".stripslashes($items->isbn)."</li>";echo "<li>bookname: ".stripslashes($items->bookname)."</li>";echo "<li>authors: ".stripslashes($items->authors)."</li>";echo "<li>prices: ".doubleval($items->prices)."</li></ul>";//$item->free();$db->close();</script></body></html>
Copy after login
### 输入关键字搜索时,地址栏显示file:///E:/CodeEdit/php/127.0.0.1/formSearch.php,找不到网页。
##但是我修改一下:$item = "javascript" ,直接在浏览器输入:127.0.0.1/formSearch.php 可以收到正确回复,在命令行输入:php formSearch.php 也可以收到正确回复。
??不知道是怎么回事??本人新手啊,刚学php才一周不到。
回复讨论(解决方案)
路径跳转有问题
浏览器输入:127.0.0.1/formSearch.php
使用的是 http 协议,http://127.0.0.1/formSearch.php
只不过浏览器友好的免去了你输入 http:// 的麻烦
而 file:///E:/CodeEdit/php/127.0.0.1/formSearch.php
是文件系统协议
显然你的 html 代码不是通过 web 服务器访问的
所以应这样写
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
