1

PHPでログインスクリプトを作成しようとしています。ユーザーは、ユーザー名とパスワードのフィールドを含むログイン フォームによってリダイレクトされます。ここでの問題は、mysqlifetch_assoc()が何も返さないことです。データベースで同じクエリを試してみましたが、期待どおりに機能します。mysql_assoc で、または数値配列として使用しようとしfetch_arrayましたが、まだ運がありません。$row[0]と の両方で戻り値にアクセスしようと$row[password]しましたが、実行すると「行が見つかりません、印刷するものがありません」と表示されるので、その時点まではすべてうまくいくと思います。

私が見逃している可能性があるものについてのヒントはありますか?

<?php 
$con=mysqli_connect('localhost','root','','site');

if(!$con)
{
die('Could not connect to database : ' . mysql.error());
}

$result=mysqli_query($con,'SELECT Password FROM users WHERE Username="$_POST[iusrname]" LIMIT 1');

if (!$result)
{
    Die("Could not successfully run query from DB: " . mysql_error());
}

$row = mysqli_fetch_assoc($result);

if (mysqli_num_rows($result) == 0)
{
    die("No rows found, nothing to print");
}


if($_POST[ipwd] == '$row[password]')
{
echo "Authentication succeeded.You will be redirected to the main page shortly";
$_SESSION['loged']=true;
$_SESSION['user']=$_POST[iusrname];
}
else
{
die("could not authenticate user");
}

mysqli_close($con);
?>
4

2 に答える 2