[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/> ";