无法在div中获取登录名和密码值

编程入门 行业动态 更新时间:2024-10-27 00:29:44
本文介绍了无法在div中获取登录名和密码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将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中获取登录名和密码值

本文发布于:2023-11-06 04:45:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562739.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:登录名   密码   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!