phyrrus9
phyrrus9

Reputation: 1467

SQL query not functioning correctly, getting no output with a perfectly fine query

code:

<?php
    session_start();

    if ( isset($_GET['user']) && isset($_GET['pass']) )
    {
            $sql = "SELECT * FROM `users` WHERE `name` = '" . $_GET['user'] . "' AND `password` = '" . $_GET['pass'] . "';";
            echo("query: $sql <br />");
            $db = mysqli_connect("localhost", "root", "<password here>", "1596");
            if (mysqli_connect_errno($db)) { die("err"); }
            $result = mysqli_query($db, $sql);
            echo($query);
            $row = mysqli_fetch_aray($result);
            echo($row);
            if ($row['name'] == $_GET['user'])
            {
                    $_SESSION['uid'] = $row['name'];
                    $_SESSION['level'] = $row['level'];
                    echo("logged in as " . $_SESSION['uid']);
            }
    }
    else
    {   
            die("Error, not enough parameters");
    }
?>

If I run that query on server, it is fine.. there is no connect error, so wondering where I went wrong

Upvotes: 0

Views: 62

Answers (1)

DevlshOne
DevlshOne

Reputation: 8457

        $db = mysqli_connect("localhost", "root", "<password here>", "1596");
        if (mysqli_connect_errno($db)) { die("err"); }
        $result = mysqli_query($db, $sql); // line corrected
        $row = mysqli_fetch_array($result); // line corrected

Upvotes: 1

Related Questions