Rumah > Artikel > pembangunan bahagian belakang > 拜天拜地 :{ 在线等
<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>
<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>
路径跳转有问题
浏览器输入: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 服务器访问的
所以应这样写