01.
<?php
require_once
(
'connection.php'
); ?>
02.
<link rel=
"stylesheet"
type=
"text/css"
href=
"css.css"
media=
"all"
/>
03.
<script type=
"text/javascript"
>
04.
function
checkvalidate(){
05.
if
(document.chatbox.question.value==
""
){
06.
alert(
"Please say something before clicking send"
);
07.
return
false;
08.
}
09.
10.
}
11.
</script>
12.
13.
<html>
14.
<body>
15.
<form align=center method=post action=
"<?$PHP_SELF?>"
name=
"chatbox"
>
16.
<!--header-->
17.
<div
class
=header><center><h1>SimKody</h1></center></div>
18.
19.
<!--chatbox-->
20.
<div
class
=chatbox>
21.
<table>
22.
<tr><td
class
=bot></td><td
class
=botchat>Hello<td></tr>
23.
</table>
24.
<?
25.
if
(isset(
$_POST
[
'question'
])) {
26.
$question
=
$_POST
[
'question'
];
27.
28.
$sql
=
"select * from kody where word like '$question' order by rand() limit 1"
;
29.
$dbquery
= mysql_query(
$sql
);
30.
31.
if
(mysql_num_rows(
$dbquery
)==0) {
32.
$error
=
"I don't know. Please teach me."
;
33.
34.
35.
36.
echo
"<table align=right>"
;
37.
echo
"<tr><td class=mechat>$question</td><td class=me></td></tr>"
;
38.
echo
"</table>"
;
39.
echo
"<br>"
;
40.
echo
"<br>"
;
41.
echo
"<br>"
;
42.
echo
"<br>"
;
43.
echo
"<table>"
;
44.
echo
"<tr><td class=bot></td><td class=botchat>$error<td></tr>"
;
45.
echo
"</table>"
;
46.
47.
}
else
{
48.
while
(
$row
=mysql_fetch_row(
$dbquery
)){
49.
$ques
=
$row
[1];
50.
$ans
=
$row
[2];
51.
echo
"<table align=right>"
;
52.
echo
"<tr><td class=mechat>$ques</td><td class=me></td></tr>"
;
53.
echo
"</table>"
;
54.
echo
"<br>"
;
55.
echo
"<br>"
;
56.
echo
"<br>"
;
57.
echo
"<br>"
;
58.
echo
"<table>"
;
59.
echo
"<tr><td class=bot></td><td class=botchat>$ans<td></tr>"
;
60.
echo
"</table>"
;
61.
}
62.
}
63.
}
64.
?>
65.
66.
</table>
67.
</div>
68.
69.
<!--chat-->
70.
<div
class
=chat>
71.
<input type=text name=question size=100 placeholder=
"Type some text......"
>
72.
<input type=button name=send value=send onClick=
"return checkvalidate()"
>
73.
</div>
74.
<!--menu-->
75.
<div
class
=menu>
76.
<table align=left width=30%>
77.
<tr>
78.
<td width=50% bgcolor=red align=center><a href=index.php>Chat</a></td>
79.
<td width=50% bgcolor=red align=center><a href=teach.php>Teach</a></td>
80.
</tr>
81.
</table>
82.
</div>
83.
</form>
84.
</body>
85.
</html>