Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 拜天拜地 :{ 在线等

拜天拜地 :{ 在线等

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


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

路径跳转有问题   非常感谢

浏览器输入: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 Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

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

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

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

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles