0

I have a telegram bot that collect telegram channel username,subscriber count and etc.. Now i need to update subscriber count of all telegram channel in my database using telegram api.

see the below code.That only updating first row in database.

if($ex[0] == '/upsubs'){
    $upsubs = mysqli_query($db,"SELECt * FROM channel");
    while($up = mysqli_fetch_assoc($upsubs)){
        $ups = $up['c_name'];
        $content1 =file_get_contents("https://api.telegram.org/bot<API_TOKER>/getChatMembersCount?chat_id=".$ups);
        $obj1 = json_decode($content1, TRUE);
        $subs1 = $obj1['result'];
        mysqli_query($db, "UPDATE channel SET c_subs = '".$subs1."' WHERE c_name = '".$ups."'");
    }
}
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Your code is open to [SQL injection](https://stackoverflow.com/q/332365/2469308) related attacks. Please learn to use [Prepared Statements](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Madhur Bhaiya Nov 04 '18 at 07:52
  • Do read: [Why is SELECT * considered harmful?](https://stackoverflow.com/q/3639861/2469308) – Madhur Bhaiya Nov 04 '18 at 07:53
  • Have you done any basic debugging - if you can't trace the code using a debugger, then something like `echo $ups.PHP_EOL;` in the loop to see what values it's using and how many times it goes round the loop. – Nigel Ren Nov 04 '18 at 08:01
  • What type of bot is that? See: https://www.sitelock.com/blog/2016/05/good-and-bad-internet-bots/ – KIKO Software Nov 04 '18 at 08:02
  • This is telegram bot – user9376877 Nov 04 '18 at 08:07

0 Answers0