Home JSON/PHP/MYSQL login connection error
Reply: 0

JSON/PHP/MYSQL login connection error

user1566
1#
user1566 Published in May 25, 2018, 6:54 pm

I'm new to PHP programming and I'm trying to test out a login page alongside JSON and MySQL. I managed to make most of it functional but I can't seem to find a way to make the query in which I verify the username and password to work.

Please help.

Here's the code:

login.js:

$(document).ready(function(){
    $('#errorLogin').hide();
    $('#formLogin').submit(function(e){
        var username=$('#inputUser').val();
        var password=$('#inputPassword').val();
        $.ajax({
            type:'get',
            dataType: 'json',
            url: 'dist/php/connection-login.php',
            data: {
                user: username,
                pass: password
            },
            success: function(e){
                console.log(e);
            }
        });
    });
});

connection-login.php:

<?php 
    $con = new mysqli("localhost", "root", "root", "solucionar_manutencoes_db");

    $lg_user=$_GET['user'];
    $lg_password=$_GET['pass'];

    if (mysqli_connect_errno()) trigger_error(mysqli_connect_error());

    $qry = mysqli_query($con, "SELECT * FROM tb_login WHERE lg_user = '$lg_user' AND lg_password = '$lg_password';");    
    $result = mysqli_fetch_assoc($qry);
    $row = mysqli_fetch_assoc($result);

    if ($row != 0) {
        $response["success"] = 1;
        echo json_encode($response);
    }
    else {
        $response["failed"] = 0;
        echo json_encode($response);
    }
?>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316589 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO