我将isset添加到我的check.php中,以摆脱未识别的索引错误.问题是,当我在登录名和密码字段中随机输入某些内容时,我在div中什么也没有得到,这是我们的目标.我究竟做错了什么?我已经一遍遍地检查了代码,却找不到正确的答案
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
这是我的login.html:
Here is my login.html:
<html> <head> <title> MYSQL </title> <script src="code.jquery/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>这是我的check.php:
Here my check.php:
<?php $login=isset($_POST['login']); $password=isset($_POST['password']); echo $login.$password; ?>推荐答案
您的代码在这里有一些问题
You have a few issues in your code here
首先,您的.click无法正常工作,因为您没有正确选择条目
Firstly your .click wont work as youre not selecting entry correctly
替换
$("entry").click(function(){使用
$("#entry").click(function(){第二,在您的php中,您将最终只返回"true"或"false",因为这是从isset()返回的内容
Secondly, in your php you are going to end up returning just "true" or "false" as that is what is returned from isset()
将您的php替换为
<?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
更多推荐
无法在div中获取登录名和密码值
发布评论