W
W
WalkersRei2018-03-21 00:06:13
PHP
WalkersRei, 2018-03-21 00:06:13

Is the data in the database not being updated?

Hello everyone, such a problem that when you enter the command / check C1BF832293C7 , you should pull out "C1BF832293C7" from the message, and update the tables with orders in the database where the chat_id is entered, the line with the order is located thanks to the identifier, in our case it is "C1BF832293C7", but something doesn't work

<?php
include $_SERVER['DOCUMENT_ROOT']."/include/config.php";

/**
 * Telegram Bot access token и URL.
 */
$access_token = '';
$api = 'https://api.telegram.org/bot' . $access_token;

/**
 * Задаём основные переменные.
 */
$output = json_decode(file_get_contents('php://input'), TRUE);
// Получение данных
$chat_id = $output['message']['chat']['id'];
$message = $output['message']['text'];

// Команды для бота
switch($message) 
{
  case '/check':
    $pieces = explode('/check ', $message);
    $sql = $db->query('UPDATE `orders` SET `chat_id` = '.$chat_id.' WHERE `identify` = "'.$pieces[1].'"');
    sendMessage($chat_id, "Вы успешно подписались на обновление статуса заказа!");					 		
    break;
  case '/start':
    sendMessage($chat_id, "Привет, я бот !");
    sendMessage($chat_id, "/check - проверка статуса заказа");
    sendMessage($chat_id, "/location - расположение на карте");
    sendMessage($chat_id, "/stock - действующие акции");
    $sql = $db->query('INSERT INTO `subscribetelegram` (`chat_id`) VALUES ("'.$chat_id.'")');		
    break;
}
// Функция отправки сообщений при получение команд
function sendMessage($chat_id, $message) {
  file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message));
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman PHP, 2018-03-21
Tag

<?php
/* ошибка тут */

var_dump($pieces[1]);
$sql = $db->query('UPDATE `orders` SET `chat_id` = '.$chat_id.' WHERE `identify` = "'.$pieces[1].'"');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question