首页 > 解决方案 > 使用 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>";
                    }
            }
    }


}

标签: php

解决方案


array_key_exists函数名有错别字。

你忘记了单词上的“s”字母存在。


推荐阅读