Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对登录问题感到困惑_Php - Fatal编程技术网

Php 对登录问题感到困惑

Php 对登录问题感到困惑,php,Php,我有一个index.php页面,用户可以在其中登录。问题是,尽管密码和用户名正确,但我无法登录。我做错了什么 PHP代码: $v = $db->prepare("select * from uyeler where uye_ad=? and uye_sifre=?"); if ($_POST) { $isim =isset( $_POST["isim"]); $sifre= isset($_POST["sifre"]); $v->execute(array($

我有一个index.php页面,用户可以在其中登录。问题是,尽管密码和用户名正确,但我无法登录。我做错了什么

PHP代码:

$v = $db->prepare("select * from uyeler where uye_ad=? and uye_sifre=?");
if ($_POST) {
    $isim =isset( $_POST["isim"]);
    $sifre= isset($_POST["sifre"]);
    $v->execute(array($isim,$sifre));
    $x = $v->fetch(PDO::FETCH_ASSOC);
    $d=$v->rowCount();
    if($d) {
        echo "Giriş Yapıldı";
    } else {
        echo "sdds";
    }
}
HTML代码:

<form action="" method="post">
    <table cellpadding="5" cellspacing="5">
        <tr>
            <td>Uye Ad</td>
            <td><input type="text" name="isim"></td>
        </tr>
        <tr>
            <td>Şifre</td>
            <td><input type="text" name="sifre"></td>
        </tr>
        <tr>
            <td><input type="submit"></td>
        </tr>
    </table>
</form>

乌耶广告
Şifre

好的,正如我从代码中看到的,我可以说你是PHP新手,我不专业,但我可以给你一些帮助

您的代码有很多问题,但我要提到一个:

  • 您的查询已完成,查询请求的变量尚未调用,因此应该在您从表单接收数据之后进行
现在,我编辑了代码,并添加了一些东西,以使其良好,没有测试它还没有,但我会,如果我没有与您合作

完整代码:

 <?php

   //connect to the database first 

    if (isset($_POST['submit'])) 
    {
        $isim = $_POST['username'];
        $sifre= $_POST['password'];

        $v = $db->prepare("SELECT * FROM uyeler where uye_ad=?");
        $v->execute(array($isim));
        $FetchUserPassword = $v->FETCH(PDO::FETCH_ASSOC);

        if (!empty($FetchUserPassword))
            {
                $password = $FetchUserPassword['uye_sifre']; // Save the fetched password inside variable 

                if( $sifre == $password )
                    {
                        echo "login done";
                    }
                else 
                    {
                        echo "Password is wrong";
                    }
            }
        else    
            {
                echo "Username is not exist";
            }

    }

?>

<form action="" method="post">
    <table cellpadding="5" cellspacing="5">
        <tr>
            <td>username</td>
            <td><input type="text" name="username"></td>
        </tr>
        <tr>
            <td>password</td>
            <td><input type="text" name="password"></td>
        </tr>
        <tr>
            <td><input type="submit" name="submit"></td>
        </tr>
    </table>
</form>

用户名
密码
我会添加一些东西在一个位(纪录片的东西),所以它可以帮助你在未来

重要提示创建登录页面时,您的代码结构应该适合用户使用:我的意思是什么

你有一个被很多人使用的登录页面,每个人都应该有用户名,在你的代码中你搜索的用户取决于他的用户名,但问题是你有很多用户,其中一些用户可能有相同的用户名,现在你会有一个大问题,因为查询将返回多行

如何通过两种方式解决此问题:

  • 与其按用户名搜索用户是否存在,不如按电子邮件搜索他们,因为他们中的每一个人都应该有一个电子邮件,通过这种方式,您可以获取一个用户,也可以不获取任何用户
  • 第二种方法是使用户名唯一,也就是说,任何人都不应该有相同的名称,您可以验证用户名是否使用Jquery,甚至在注册页面中
第三点也是最后一点:

  • 确保在用户注册时对密码进行加密,这将使密码保持加密和安全,以防您的数据库遭到黑客攻击
您正在$d变量中存储行数。如果未找到匹配项,它将始终为零;如果在数据库表中找到数据,它将始终大于零。 修改您的if条件:

if( isset($d)  && $d != 0 ){
        echo    "Giriş Yapıldı";
    }else {
        echo "sdds";
 }

好吧,你应该让MySQL密钥大写<代码>从
中选择
,如下所示。这是一个很好的实践。首先要确认你是否得到了任何结果。使用
var\u dump()
如果您正在获取,则将if条件更改为
if($d==1)
然后执行其余操作