<?
//fopen("search.html",'a');
echo "<a href=\"search.php\">Enter The Search Web.";
//fopen("search_result.php",'w');
//get_magic_quotes_gpc魔术引擎是否开启
?>
这是search.php
<?
require("page.inc");
$searcher=new page();
$searcher->content="<font size=\"+5\">Book-O-Rama Catalog Search</font><br />
<form action=\"search_result.php\" method=\"post\">
Choose Search Type<br />
<select name=\"search_type\">
<option value=\"Author\">Author</option><br />
<option value=\"Title\">Title</option><br />
<option value=\"ISBN\">ISBN</option><br />
</select><br />
Enter search Term:<br />
<input name=\"searchterm\" type=\"text\" size=\"40\" /><br />
<input name=\"submit\" value=\"Search\" type=\"submit\">
</form>
";
$searcher->display();
?>
page.inc里面改一句话
public $button=array("home"=>"home.php",
"contact"=>"contact.php",
"service"=>"services.php",
"sitemap"=>"sitemap.php",
"news"=>"news.php",
"search"=>"search.php");
这是search_reasult.php的页面
<?
require("page.inc");
$search_result=new page();
$search_type=$_POST['search_type'];
$searchterm=$_POST['searchterm'];
$content="";
if(!get_magic_quotes_gpc()){
$searchterm=addslashes($searchterm);
$search_type=addslashes($search_type);
}
if($searchterm==''){
$search_result->content="Please Input The Search Iterm";
$search_result->display();
return;
}
@$con=new mysqli('localhost','lustudy_web','123456','lustudy');
if(mysqli_connect_error()){
$content= "ERROR:Can not connect database.Please Try Again Later";
exit;
}
$sqlstr="select * from books where ".$search_type." like '%".$searchterm."%'";
$web_reasult=$con->query($sqlstr);
$reasult_num=$web_reasult->num_rows;
$content.= "Number of books found : ".$reasult_num."<br /><br />";
//if($reasult_num==0){exit;}
for($i=0;$i<$reasult_num;$i++){//什么时候用逗号什么时候用分号来着
$row=$web_reasult->fetch_assoc();
$content.= ($i+1)." Title: ".$row['title']."<br />
Athor : ".$row['author']."<br />
ISBN : ".$row['isbn']."<br />
Price : ".$row['price']."<br /><br />";
}
$content.="<a href=\"search.php\"><font color=\"#330000\">返回</font></a><br /><br />";
$web_reasult->free();
$con->close();
$search_result->content=$content;
$search_result->display();
/*11.4绑定参数插入数据 prepared方法*/
require("database.inc");
$con=new mysqli($lu_host,$lu_user,$lu_psw,$lu_db);
//use prepared insert (bind_param)
$isbn='1-111-11111-7';
$author='wenbo';
$title='how to kill you';
$price=71;
$str2="insert into books values (?,?,?,?)"; //use ? to replace the param
$result_check=$con->query("select * from books where isbn='".$isbn."'");
if($result_check->num_rows != 0){echo "The Book is exist.<br />";} //check if the record is exist.
else{
$result2=$con->prepare($str2);
$result2->bind_param("sssd",$isbn,$author,$title,$price);
$result2->execute();
echo $result2->affected_rows.'book inserted into database';
}
//use prepared to select(bind_result)
//1.select string
$selectstr="select isbn,title,author,price from books";
//2.prepare select
$result3=$con->prepare($selectstr);
//3.bind result
$result3->bind_result($isbn2,$title2,$author2,$price2);
//4.excute the select
$result3->execute();
//5.echo the result use while
while($result3->fetch()){
echo "ISBN:$isbn2 <br />";
echo "Title:$title2 <br />";
echo "Author:$author2 <br />";
echo "Price:$price2 <br /><br />";
}
//it has a problem Price:30.239999771118 should be 30.24,dont know why
//i should use decimal.http://blog.csdn.net/howroad/article/details/78202832
/*11.5使用php与数据库交互的其他借口*/
//下载pear http://pear.php.net/go-pear.phar
//require_once("Mail.php");
//因为pear 安装一直失败,所以暂时不研究这一篇了……
?>
应用十一章的mysql思想自己做了一个网站,相关的信息都在下一篇文章里。
http://blog.csdn.net/howroad/article/details/78134194