php - 使用 array_key_exist 检查用户传递的值是否存在于数组中。澄清 array_key_exist
问题描述
我已经按照我的逻辑编写了代码。我想检查用户名和密码是否有效并提示“成功登录”消息。当我运行它时,我发现“调用未定义函数 array_key_exits()”错误。据我了解, array_key_exists 接受一个密钥作为参数, $_POST["txtUsername"] 持有我的密钥。
//Login is button
if(isset($_POST['Login']))
{
$user = htmlspecialchars(trim($_POST["txtUsername"]));
$pass = htmlspecialchars(trim($_POST["txtPassword"]));
//to go through all usernames and passwords in the array:
if(array_key_exits($_POST["txtUsername"], $login))
{
foreach($login as $username => $password)
{
//to check if username and password is matching:
if($user == $username && $pass == $password)
{
//if username and password is matching:
echo "<h1>You have successfully logged in! \n</h1>";
}
else
{
echo "<h1>Sorry, wrong information has been entered!</h1>";
}
}
}
}
解决方案
array_key_exists函数名有错别字。
你忘记了单词上的“s”字母存在。
推荐阅读
- python - Keep running a process in a Python Lambda (AWS) after returning a response
- selenium - 如何单击烤面包机消息下的元素
- gitlab - 如何在 Gitlab CI 管道中包含带有预定义变量引用的文件
- amazon-web-services - DynamoDB - DTO 中不允许使用对象数据类型
- vue.js - v 模型的微小 MCE 所见即所得问题 | 只有谷歌浏览器
- vb.net - 显示从字符串到 Double 类型的错误转换无效,输入字符串格式不正确
- javascript - 当数组的索引值不唯一时使用什么?
- r - Left_join 太大而无法处理
- reactjs - MUI 选择标签未正确隐藏
- python - 在 Tensorflow/Keras 中将 NN 输出的最大值限制为正