发布时间:2015-05-27 19:31:32作者:知识屋
[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="search.php" method="post">
请输入您要查找的英文单词:<br/>
<input type="text" name="enword"/><br/>
<input type="submit" value="提交"/><br/>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="search.php" method="post">
请输入您要查找的英文单词:<br/>
<input type="text" name="enword"/><br/>
<input type="submit" value="提交"/><br/>
</form>
</body>
</html>[php] view plaincopyprint?
<?php
class DicTool{
private $conn;
private $host = "localhost";
private $user = "root";
private $password = "123";
private $db = "test";
//构造函数,初始化数据,连接数据库
function __construct(){
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn){
die("连接数据库失败".mysql_error());
}
//选择数据库
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
function findchword($enword){
$sql = "select * from words where enword ='".$enword."'limit 0,10";
$res = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$res){
return 0;//失败
}else{
$row = mysql_fetch_assoc($res);
return $row['chword'];
}
}
}
<?php
class DicTool{
private $conn;
private $host = "localhost";
private $user = "root";
private $password = "123";
private $db = "test";
//构造函数,初始化数据,连接数据库
function __construct(){
$this->conn = mysql_connect($this->host, $this->user, $this->password);
if (!$this->conn){
die("连接数据库失败".mysql_error());
}
//选择数据库
mysql_select_db($this->db,$this->conn);
mysql_query("set names utf8");
}
function findchword($enword){
$sql = "select * from words where enword ='".$enword."'limit 0,10";
$res = mysql_query($sql,$this->conn) or die(mysql_error());
if (!$res){
return 0;//失败
}else{
$row = mysql_fetch_assoc($res);
return $row['chword'];
}
}
}
[php]
<?php
header("Content-Type: text/html; charset=UTF-8");
include_once 'DicTool.class.php';
$dicTool = new DicTool();
if (isset($_POST['enword'])){
$chword = $dicTool->findchword($_POST['enword']);
if ($chword){
echo $_POST['enword']."对应的中文意思是:".$chword."<br/>";
}else{
echo "未查询到结果!<br/>";
}
}else{
echo "未获取任何输入!<br/>";
}
echo "<a href='find.html'>点击返回<a/><br/>";
<?php
header("Content-Type: text/html; charset=UTF-8");
include_once 'DicTool.class.php';
$dicTool = new DicTool();
if (isset($_POST['enword'])){
$chword = $dicTool->findchword($_POST['enword']);
if ($chword){
echo $_POST['enword']."对应的中文意思是:".$chword."<br/>";
}else{
echo "未查询到结果!<br/>";
}
}else{
echo "未获取任何输入!<br/>";
}
echo "<a href='find.html'>点击返回<a/><br/>";
如何对PHP文件进行加密方法 PHP实现加密的几种方式介绍
php生成圆角图片的方法 电脑中php怎么生成圆角图片教程
用PHP构建一个留言本方法步骤 php怎么实现留言板功能
php中三元运算符用法 php中的三元运算符使用说明
php文件如何怎么打开方式介绍 php文件用什么打开方法
PHP怎么插入数据库方法步骤 php编程怎么导入数据库教程
如何安装PHPstorm并配置方法教程 phpstorm安装后要进行哪些配置
PHP 获取远程文件大小的3种解决方法 如何用PHP获取远程大文件的大小
20个实用PHP实例代码 php接口开发实例代码详细介绍
如何架设PHP服务器方法步骤 怎么搭建php服务器简单教程