《PHP MySQL和WEB开发》笔记第十一章
来源:互联网 发布:层次方框图软件 编辑:程序博客网 时间:2024/05/22 13:02
<?//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 whilewhile($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
阅读全文
0 0
- 《PHP MySQL和WEB开发》笔记第十一章
- PHP和MySQL WEB开发学习笔记
- 《PHP和MySQL Web应用开发》笔记
- 《PHP和MySQL Web开发》学习笔记:1~3章
- 《PHP和MySQL Web开发》学习笔记:4~5章
- 《PHP和MySQL WEB开发》第一、二章笔记
- 《PHP和MySQL WEB开发》第三章笔记
- 《PHP和MySQL WEB开发》第四章笔记
- 《PHP和MySQL WEB开发》第六章笔记
- 《PHP和MySQL WEB开发》笔记第七章
- 《PHP MySQL和WEB开发》第八章笔记
- 《PHP MySQL和WEB开发》第九章笔记
- 《PHP MySQL和WEB开发》第十章笔记
- PHP学习笔记《PHP和MySQL web 开发》
- 《php和mysql web开发》笔记——第8章 设计Web数据库
- 《php和mysql web开发》笔记——第9章 创建Web数据库
- 《php和mysql web开发》笔记——第1章PHP快速入门
- 《php和mysql web开发》笔记——第6章 面向对象的PHP
- Python 列表生成式
- cmder使用配置记录
- Vue 中阻止冒泡和默认事件
- angualr4基础之组件生命周期
- 分类器评价指标——ROC曲线和AUC值
- 《PHP MySQL和WEB开发》笔记第十一章
- JAVA开发中字节转换问题(byte数组byte数组、合并、转换16进制)
- Eclipse:An internal error occurred during: "Build Project". GC overhead limit exceeded
- Couldn't reserve space for cygwin's heap, Win32 error 0
- 字符串的全排列问题的解决方法
- Ubuntu16.04环境下安装CUDA、cudnn、Caffe、Tensorflow、pytorch
- socket、tcp、udp、http 的认识及区别
- linux Samba共享,图形界面配置
- 洛谷P3606 [USACO17JAN]Building a Tall Barn建谷仓