0

I have a problem with this code.

I want select lang from Users table and if was fa send a message to user with telegram bot can u help me plz

// Create connection
$sconn = new mysqli($dbservername, $dbusername, $dbpassword, $dbname);
// Check connection
if ($sconn->connect_error) {
    die("</br>Connection failed: " . $sconn->connect_error);
}
else{
    echo "</br>Connected successfully</br></br></br>";

} 
$sconn->query("set names utf8mb4");
$ssql = "SELECT lang FROM Users WHERE user_id=$user_id";
$result = $sconn->query($ssql);


if($ssql == "fa"){
       var_dump(bot('sendMessage',[
        'chat_id'=>$chat_id,
        'text'=>"test",
        ]));
}
$sconn->close();
S.I.
  • 3,250
  • 12
  • 48
  • 77
Mhdi
  • 11
  • 5

1 Answers1

0

The problem is this line:

if($ssql == "fa"){

You've used $ssql earlier in the script to store your SQL - checking for "fa" will never return true.

You need to use mysqli_fetch_assoc to get the data - there's a short example at https://www.w3schools.com/php/func_mysqli_fetch_assoc.asp

thirtyish
  • 395
  • 3
  • 18