PHP - 我的SQL查询不接受多个php变量[重复]

below is mysql query, the problem is the query only works as long as there is only one php variable such as

 Select * From student where Account = ".$username."

but if I change the code to be as below, I got the error

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given.

What might be the problem here, please help me.

    $result = $con->query("SELECT * FROM '.$role.' WHERE Account = '.$username.' AND password = '.$password.' AND IsApproved = '.$approval.'");

    if(mysqli_num_rows($result) == 1) {
      $_SESSION['username'] = $username;
      header('Location: include/test.php');
    }
    else {
      echo "Account is invalid";
    }
  }

EDIT : PROBLEM SOLVED - Answer by Dhaval Dave

 $result = $con->query("SELECT * FROM {$role} WHERE Account = '{$username}' AND password = '{$password}' AND IsApproved = '{$approval}'");

Thanks alot to everyone for helping me all the suggestion, I appreciated what you guys did to me. Thanks alot x1000

</div>
$result = $con->query("SELECT * FROM ".$role." WHERE Account = ".$username." AND password = ".$password." AND IsApproved = ".$approval.");

Please try

<?php
$result = $con->query('SELECT * FROM "'.$role.'" WHERE Account = "'.$username.'" AND password = "'.$password.'" AND IsApproved = "'.$approval'"');

You need to pass single quotes when you are passing string in sql condition.

$result = $con->query("Select * From student where Account = '".$username."' AND password = '".$password."' ");

try this,

$role = trim($role);
$result = $con->query("SELECT * FROM {$role} WHERE Account = '{$username}' AND password = '{$password}' AND IsApproved = '{$approval}'");