<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>在线词典</title>
<link href="shouye.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="toubu"><h1>在线词典精彩无限</h1></div>
<div class="zhongjian"><img src="1.jpg"/>
<H1>查询英文</H1>
<form action="wordprocess.php" method="post" >
请输入英文:<input name="enword" type="text" />
<input name="type" type="hidden" value="search1" />
<input type="submit" value="查询" />
</form>
<H1>查询中文</H1>
<form action="wordprocess.php" method="post" >
请输入中文:<input name="chword" type="text" />
<input name="type" type="hidden" value="search2" />
<input type="submit" value="查询" />
</form></div>
<div class="zuihou">
<div>山东省邵氏科技股份有限公司</div>
<div class="zuihou">地址:山东省济南市山大北路。技术支持:邵先生 邮箱: </div>
</div>
</body>
</html>
@charset "utf-8";
.zuihou {
font-family: "Comic Sans MS", cursive;
font-size: 15px;
text-align: center;
background-color: #CCC;
float: left;
height: 20%;
width: 100%;
}
.toubu{
font-size: 24px;
text-align: center;
background-color: #CCC;
float: left;
height: 20%;
width: 100%;
font-family: Verdana, Geneva, sans-serif;
}
.zhongjian {
position: relative;
text-align: center;
border: thin solid silver;
width: 950px;
height: inherit;
background-color: #FF9;
margin: auto;
padding: 1px;
background-position: center;
clear: both;
float: none;
}
<?Php
header("Content-type:text/html;charset=utf-8");//设置浏览器显示的乱码问题
require_once("412.php");
if(isset($_POST[‘type‘])){
$type=$_POST[‘type‘];
}else{
echo"输入为空";
echo"<a href=‘mainview.php‘>返回重新查询</a>";
}
if($type=="search1"){
//接受英文单词
if(isset($_POST[‘enword‘])){$en_word=$_POST[‘enword‘];}else{//主义 $_POST 函数是分大小写的
echo"输入为空";
echo"<a href=‘mainview.php‘>返回重新查询</a>";
}
//看看数据库中有没有这条记录
$sql="select chword from words where enword=‘".$en_word."‘ limit 0,1";
$sqltool=new sqltool();
$res=$sqltool->execute_dql($sql);
if($row=mysql_fetch_assoc($res)){//主义:此处用的是关联数组
echo $en_word."对应的中文意思是: ".$row[‘chword‘];
echo"<br /><a href=‘mainview.php‘>返回重新查询</a>";}
else{
echo"查询没有这个词条";
echo"<br /><a href=‘mainview.php‘>返回重新查询</a>";}
mysql_free_result($res);
}
if($type=="search2"){
//接受中文
if(isset($_POST[‘chword‘])){$ch_word=$_POST[‘chword‘];}else{//主义 $_POST 函数是分大小写的
echo"输入为空";
echo"<a href=‘mainview.php‘>返回重新查询</a>";
}
//看看数据库中有没有这条记录
$sql="select enword from words where chword like ‘%".$ch_word."%‘";
$sqltool=new sqltool();
$res=$sqltool->execute_dql($sql);
if(mysql_num_rows($res)){
while($row=mysql_fetch_assoc($res)){//主义:此处用的是关联数组
echo $ch_word.‘对应的意思是: ‘.$row[‘enword‘];
echo"<br />";
}
echo"<br /><a href=‘mainview.php‘>返回重新查询</a>";}
else{
echo"查询没有这个词条";
echo"<br /><a href=‘mainview.php‘>返回重新查询</a>";}
mysql_free_result($res);
}
?>
<?php //412.php
class sqltool{
private $conn;
private $host="localhost";
private $user="root";
private $password="";
private $db="worddb";
function sqltool(){
$this->conn=mysql_connect($this->host,$this->user,$this->password);
if(!$this->conn){
die("链接数据库失败".mysql_error());
}
mysql_select_db($this->db,$this->conn)or die(mysql_error());
mysql_query("set names utf8");
}
function execute_dql($sql){
$res=mysql_query($sql);
return $res;
}
function execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return 0;
}
else{
if(mysql_affected_rows($this->conn)>0){
return 1;}
else{
return 2;
}
}
mysql_close($conn);}
}
?>
原文地址:http://blog.csdn.net/u013861473/article/details/28010713