简体   繁体   中英

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

        $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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM