Compare all rows in SQL table with a string - PHP - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, September 5, 2022

Compare all rows in SQL table with a string - PHP

I want to get the contents of all rows in the SQL table and compare them with the contents of an html input. If I enter in the input the user and password of the first row the addressing to the page happens, if I enter the user and password of the second row nothing happens.

Php code:

"""

        include "config.php";
        $i = 0;
        $sql = "SELECT * FROM users";
        $result = mysqli_query($connection, $sql);
        $rowcount = mysqli_num_rows($result);
        while($row = $result->fetch_assoc()) {
            $userRow[$i] = $row["username"];
            $passRow[$i] = $row["password"];
            $complete[$i] = $row["username"]." ".$row["password"];
            $i++;
        }
        
        for ($i = 0; $i < $rowcount; $i++) {
            echo "<br>".$complete[$i]."</br>";
            echo "<br>$i</br>";
            if ($userRow[$i] == $username && password_verify($password, $passRow[$i])) { 
                echo "<br>Logged in</br>";
            }
        }

"""



source https://stackoverflow.com/questions/73602466/compare-all-rows-in-sql-table-with-a-string-php

No comments:

Post a Comment