I'm pretty sure this code has something wrong with it:
$sql="select * from user where username={$_POST['username']}AND pwd= {$_POST['password']}";
$r = mysqli_query($link,$sql);
if($r)
{
$_SESSION['loggedin']=true;
echo "Welcome". $_POST['username'];
}