拜天拜地 :{ 在线等

WBOY
Release: 2016-06-23 14:00:11
Original
1040 people have browsed it

<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 服务器访问的
所以应这样写


而能保证从服务器上运行时,只需写作

路径跳转有问题   非常感谢

浏览器输入: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 服务器访问的
所以应这样写


而能保证从服务器上运行时,只需写作


非常感谢,可以了。 :{
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template