Reputation: 9
i need to insert some data to database which is $user_id and $username
i used telegram method to define them :
$user_id = $message->from->id;
$username = $message->from->username;
them made this code :
$connect = mysqli_connect("xxx","xxx","xxx","xxx");
$result = mysqli_query($connect,"SELECT * FROM users WHERE id = '$user_id'");
$rowcount=mysqli_num_rows($result);
if($text == '/start' and strpos($check, '"status":"left"') == TRUE){
if($rowcount = 0){
mysqli_query($connect,"INSERT INTO
users (id,username,points)
VALUES ('$user_id','$username','0')");
}
bot('sendMessage',[
'chat_id'=>$chat_id,
'text'=>'a text',
'reply_markup'=>json_encode([
'inline_keyboard'=>[
[['text'=>'my text','url'=>'my link']]
]
])
]);
}
the problem is that the query doesn't insert anything to the table, I checked $rowcount and it returns a valid value.
also checked $username and $user_id methods.
Upvotes: 0
Views: 4859
Reputation: 11
In my situation the reason for not inserting rows in database was that db user wasn't associated with the database.
Also maybe
strpos($check, '"status":"left"') === TRUE)
Upvotes: -1
Reputation: 91
check your comparison
if($rowcount = 0){
use double equal ==
Upvotes: 4