Home » Php » Login log-in with anything i type but not with db content

Login log-in with anything i type but not with db content

Posted by: admin October 26, 2017 Leave a comment


Hi everybody im new here, and im new in the website world, im trying my best to get better so my first goal is to make a Login, i had a lot of problem trying to make a good one to my own, but it keep getting me a lot of issues, right now my code is working fine but everytime i want to log-in it just log with anything for example in my db i have (admin, admin) but my website wont work with the mysql i can type (asdasd,asdasdasd) and it log-in, been trying to mantain the session_start(); and the $_SESSION < i know this is the problem but i cant fix it…. so please help me.

if(!isset($_SESSION['bttLogin'])) {
    $_SESSION['bttLogin'] = @$_POST['user'];
    $username = @$_POST['user']; 
    $password = @$_POST['pass'];

    $result = mysqli_query($con, "SELECT * FROM USERS WHERE USERNAME = 
'$username' AND PASSWORD = '$password' ")
                    or die("Failed to query database 

    $row = mysqli_fetch_array($result);


        <?php echo $_SESSION['bttLogin']; ?>
            if(isset($_SESSION['bttLogin']))  {
                    echo "Welcome ".$_SESSION['bttLogin'];
                    echo "
                    <div class='form-row align-items-center'>
                    <div class='col-sm-0'>
                    <a href='test2.php' class='btn btn-warning '>Ver Perfil </a>
                    <div class='col-auto mb-0 mb-sm-0'>
                    <a href='logout.php' class='btn btn-danger '>Salir</a> 
            } else  { ?> 
                     <form method='POST' action='index.php'>
                            <div class='form-row align-items-center'>
                            <div class='col-sm-4'>
                            <input class='form-control mb-2 mb-sm-0' placeholder='Usuario' type='text' id='user' name='user'> 
                            <div class='col-sm-4 mb-2 mb-sm-0'>
                            <input class='form-control' placeholder='password' type='password' id='pass' name='pass'> 
                            <div class='col-auto'>
                            <button type='submit' class='btn btn-info' name='bttLogin' value='login'>ENTRAR</button>
                            <button type='submit' class='btn btn-warning'>REGISTRAR</button>
                            <button type='submit' class='btn btn-primary'>LOGOUT</button>