0

I added isset to my check.php to get rid of an unidentified index error. The thing is, I’m not getting anything in div when I type something random in the login and password fields which is the goal here. What am I doing wrong? I’ve checked the code over and over and I can’t get the right answer

Here is my 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 my check.php:

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

echo $login.$password;



?>
Reporter
  • 3,897
  • 5
  • 33
  • 47

1 Answers1

0

You have a few issues in your code here

Firstly your .click wont work as youre not selecting entry correctly

Replace

$("entry").click(function(){

with

$("#entry").click(function(){

Secondly, in your php you are going to end up returning just "true" or "false" as that is what is returned from isset()

Replace your php with

<?php
    if(isset($_POST['login']) && isset($_POST['password'])){
        $login=$_POST['login'];
        $password=$_POST['password'];

        echo $login.$password;
    }
?>

This will check if login and password is set before echoing

or if you want an easier but worse way

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

    echo $login.$password;
?>

This simply suppresses your errors, this is more frowned upon though

GiantJelly
  • 298
  • 2
  • 15