小词典(php)

php中文网
发布: 2016-06-23 13:28:30
原创
1157人浏览过

  • 查询前台页面(enword.php)

  • <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head><body><img  src="1.png"/ alt="小词典(php)" ><h1>英汉词典</h1><form action="enw.php" method="post">请输入英文:<input type="text" name="enword" /><input type="submit" value="查询" name="serch" /></form></body></html>
    登录后复制

    2.编写数据库操作类(ewTool.class.php)

    <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head><body><?phpclass enwTool{    protected $conn;    private $host="127.0.0.1";    private $user="root";    private $password="";    protected $bd="php_dic";    //构造函数声明变量    public function __construct()    {        $this->conn=mysql_connect($this->host,$this->user,$this->password) or die("链接失败");        mysql_select_db($this->bd);        mysql_query("set names utf8");    }    //查询数据库语句    public function dql($sql)    {        //$res为资源型        $res=mysql_query($sql,$this->conn) or die(mysql_error());        return $res;    }    //添加数据库语句    public function dml($sql)    {        $b=mysql_query($sql,$this->conn);        if(!$b)        {            return 0;        }        else        {            if(mysql_affected_rows($this->conn))            {                return 1;            }            else            {                return 2;            }        }        }}?></body></html>
    登录后复制

    3.编写添加前台页面(add.php)

    <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head><body><h1>请添加英汉</h1><form action="dml.php" method="post">请输入英文:<input type="text" name="eng"/>请输入中文:<input type="text" name="chi"><input type="submit" value="添加"></form></body></html>
    登录后复制

    4.便面dml语句代码。

    <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"></head><body><?phprequire_once "enwTool.class.php";$eng=$_REQUEST['eng'];$chi=$_REQUEST['chi'];if(isset($eng)||isset($chi)){    $sql="insert into dic (enword,chword) values ('$eng','$chi')";    $p=new enwTool();    $res=$p->dml($sql);    if($res==0)    {        echo "老兄没有你没有写东西吧!";    }    else if($res==1)    {        echo "恭喜添加成功!";        echo "<a href='enword.php'>返回</a>";    }    else if($res==2)    {        echo "你添加有误!";    }}else{    echo"请输入";    echo"<a herf='add.php'>返回</a>";   }?></body></html>
    登录后复制

    以上就是php代码啦。

    立即学习PHP免费学习笔记(深入)”;

    mysql操作也是至关重要的哦!

  • 创建数据库

  • create database php_dic;

    2.创建一张表

    create table dic(

    dic_id int primary key auto_increment,

    小爱开放平台
    小爱开放平台

    小米旗下小爱开放平台

    小爱开放平台 23
    查看详情 小爱开放平台

    enword varchar(20) not null default'',

    chword varchar(200) not ull default''

    )set character utf8;

    3.设置字符集

    set names utf8;

    4.设置数据库表编码和表编码

    alter database php_dic  character set utf8;

    alter table dic character set utf8;

    然后就可以查询和添加啦~~

    PHP速学教程(入门到精通)
    PHP速学教程(入门到精通)

    PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

    下载
    来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    最新问题
    开源免费商场系统广告
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送
    PHP中文网APP
    随时随地碎片化学习

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号