I am working with a PHP based open source chat bot and trying to save the message the end user typed in to the bot that triggered the "fallback" function. so that I can see what sorts of things people are asking the bot that I might not of built logic/answers to. However my issue is the mysql insert does not seem to work. if I take my actual query and past it into phpmyadmin the query works but in the php page its not working so trying to figure out what it might not be working.
Here is my full code
<?php
require_once('../vendor/autoload.php');
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Middleware\ApiAi;
DriverManager::loadDriver(\BotMan\Drivers\Web\WebDriver::class);
$config = [
'web' => [
'matchingData' => [
'driver' => 'web',
],
]
];
$botman = BotManFactory::create($config);
$dialogflow = ApiAi::create('123abc')->listenForAction();
// Apply global "received" middleware
$botman->middleware->received($dialogflow);
//lets open connection to the mysql database
$chatdbconn = mysqli_connect("localhost","root","root","chatdb");
$chatdatetime = date('Y-m-d H:i:s');
/////////////////////////////////////
// DIALOG FLOW
/////////////////////////////////////
$botman->hears('hello|customerservice_contact|brand_feeling', function (BotMan $bot) {
// The incoming message matched the "my_api_action" on Dialogflow
// Retrieve Dialogflow information:
$extras = $bot->getMessage()->getExtras();
$apiReply = $extras['apiReply'];
$apiAction = $extras['apiAction'];
$apiIntent = $extras['apiIntent'];
$bot->typesAndWaits(2);
$bot->reply($apiReply);
})->middleware($dialogflow);
$botman->fallback(function($bot) {
global $chatdbconn;
$phrase = $bot->getMessage();
$unknownphrase = mysqli_real_escape_string($chatdbconn, $phrase->getText());
//$created_on = date('Y-m-d H:i:s');
mysqli_query($chatdbconn, "INSERT into chatbot_unknown_phrases(the_phrase) VALUES('$unknownphrase')");
$bot->typesAndWaits(2);
$bot->reply('Sorry, I did not understand the command.');
});
// Start listening
$botman->listen();
?>