I’m working to a Telegram bot and I want to insert a string, which is a string of a message, into the database, but it doesn’t work and I can’t understand why…
This is the code I’m using:
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$token = "TOKEN";
$website = "https://api.telegram.org/bot".$token;
$updates = file_get_contents('php://input');
$updates = json_decode($updates, TRUE);
$text = $updates['message']['text'];
$chat_id = $updates['message']['chat']['id'];
switch($text){
//other cases...
case "/test":
$str = $updates['message']['reply_to_message']['text'];
$insert = 'INSERT INTO test VALUES (\'\',"'.$str.'");';
mysqli_query($conn,$insert);
sendMessage($chat_id, $str);
break;
//other cases...
}
//sendMessage($chat_id, $text);
function sendMessage($id, $message){
$url = $GLOBALS[website]."/sendMessage?chat_id=".$id."&text=".urlencode($message);
file_get_contents($url);
}
?>
I’m waiting for a response…