-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.php
30 lines (25 loc) · 815 Bytes
/
bot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!-- php start for bot-->
<!-- step 1 => create database for response and user messages -->
<!-- step 2 => create a connection -->
<?php
// server = localhost
// username = root
// password = "" (blank)
// database Name = your database name
$conn = mysqli_connect("127.0.0.1:3307","root","","chatbot");
if($conn){
$user_messages = mysqli_real_escape_string($conn, $_POST['messageValue']);
$query = "SELECT * FROM chatbot WHERE message LIKE '%$user_messages%'";
$runQuery = mysqli_query($conn, $query);
if(mysqli_num_rows($runQuery) > 0){
// fetch result
$result = mysqli_fetch_assoc($runQuery);
// echo result
echo $result['response'];
}else{
echo "Sorry can't be able to understand you!";
}
}else{
echo "connection Failed " . mysqli_connect_errno();
}
?>