Php --- mysql simple application --- online dictionary

Source: Internet
Author: User

[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">
Enter the English word you want to search for: <br/>
<Input type = "text" name = "enword"/> <br/>
<Input type = "submit" value = "submit"/> <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">
Enter the English word you want to search for: <br/>
<Input type = "text" name = "enword"/> <br/>
<Input type = "submit" value = "submit"/> <br/>
</Form>
</Body>
</Html> [php] view plaincopyprint?
<? Php
 
Class DicTool {
 
Private $ conn;
Private $ host = "localhost ";
Private $ user = "root ";
Private $ password = "123 ";
Private $ db = "test ";
 
// Constructor, initialize data, connect to database
Function _ construct (){

$ This-> conn = mysql_connect ($ this-> host, $ this-> user, $ this-> password );
If (! $ This-> conn ){
Die ("failed to connect to Database". mysql_error ());
}
// Select a database
Mysql_select_db ($ this-> db, $ this-> conn );
Mysql_query ("set names utf8 ");
}
 
Function findchword ($ enword ){

$ SQL = "select * from words where enword = '". $ enword. "'limit ";

$ Res = mysql_query ($ SQL, $ this-> conn) or die (mysql_error ());

If (! $ Res ){
Return 0; // failed
} 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 ";

// Constructor, initialize data, connect to database
Function _ construct (){

$ This-> conn = mysql_connect ($ this-> host, $ this-> user, $ this-> password );
If (! $ This-> conn ){
Die ("failed to connect to Database". mysql_error ());
}
// Select a database
Mysql_select_db ($ this-> db, $ this-> conn );
Mysql_query ("set names utf8 ");
}

Function findchword ($ enword ){

$ SQL = "select * from words where enword = '". $ enword. "'limit ";

$ Res = mysql_query ($ SQL, $ this-> conn) or die (mysql_error ());

If (! $ Res ){
Return 0; // failed
} 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']. "The corresponding Chinese meaning is:". $ chword. "<br/> ";
} Else {
Echo "no results found! <Br/> ";
}
} Else {
Echo "no input is obtained! <Br/> ";
}
Echo "<a href='find.html '> Click Back <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']. "The corresponding Chinese meaning is:". $ chword. "<br/> ";
} Else {
Echo "no results found! <Br/> ";
}
} Else {
Echo "no input is obtained! <Br/> ";
}
Echo "<a href='find.html '> Click Back <a/> <br/> ";

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.