1

So moving on from my last question yet again i have another problem. Here is the link for that however i will put the codes here too:Not getting login and password values in div So i'm trying to get the 'number' of the user im logging into as from the input fields which i have made in phpmyadmin. When i enter something completely random i get 0 as that randomly entered name isnt in my database, however when i enter the actual login and password from one of the users i get 0 instead of 1 which would mean that that user was found from the database. im not sure if i can link the database but here it is: http://localhost/phpmyadmin/sql.php?db=mysqldb1&table=users&token=dbc781132ba546cedab4644522745917&pos=0 here are the codes: here is login.html

<html>
    <head>
        <title> MYSQL </title>
        <script
         src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous">
        </script> 
    </head>
    <body>
    <div id="status"></div>
    <input id="login" placeholder="Login"><br>
<input type="password" id="pass" placeholder="Password"  <br>
    <button id="entry"> Login </button>
    <script>
    $("#entry").click(function(){
        $.post("check.php", {login: $("#login").val(), password: $("#pass").val()},
        function(result){
        $("#status").html(result);

    })
})
    </script>
    </body>
 </html>

here is the php code

<?php
$login=$_POST['login'];
$password=$_POST['password'];

echo $login.$password;

require "config/con1.php";

$sql= "SELECT id FROM users WHERE login='$login' AND password='$password' ";

$result=mysqli_query($con, $sql);
$value = mysqli_num_rows($result);
echo $value;

?>

1 Answers1

0

The php will return the number of rows. If you are looking for id you might need to fetch it.

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row['Column_in_database'];
    }
}
Parth Manaktala
  • 1,112
  • 9
  • 27