【解決方法】SQL 構文にエラーがあります。


Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'lt where uname= '' and password=''' at line 1 in F:\New folder\htdocs\login\login.php:20 Stack trace: #0 F:\New folder\htdocs\login\login.php(20): mysqli_query(Object(mysqli), 'select * lt whe...') #1 {main} thrown in 

私が試したこと:

<?php

if($_POST)
{
   $host="localhost";
   $user="root";
   $password="";
   $database="logintest";
   $connection=mysqli_connect($host,$user,$password,$database);


   
// include ('connection.php');
$user=$_POST['uname'];
$pass=$_POST['pasw'];

$query="select * lt where uname= '$user' and password='$pass'";

$result=mysqli_query($connection, $query);

$Nrows=mysqli_num_rows($result);
if($Nrows==1)
{  session_start();
while($Nrows=mysqli_fetch_assoc($result))
{
    $_SESSION['user']=$Nrows['uname'];
    $_SESSION['pass']=$Nrows['password'];
    $_SESSION['rol']=$Nrows['rol'];
}

header("location:index.php");

}
else
{
    echo 'wrong user name or password';
}
?>



<?php
 if($_POST)
 {
    $host="localhost";
    $user="root";
    $password="";
    $database="logintest";

 }

}
?>



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <form action="login.php" method="POST"> 
<input type="text" name="uname" id="un">
<label for="un">user name</label>
<br>
<br>
<input type="password" name="pasw">
<label for="pasw">password</label>

<input type="submit">


</form> 
</body>
</html>

解決策 1

あなたは逃した FROM 「*」とテーブル名の間のキーワード。 しかし、解決すべきもっと重要な問題があります。 パスワードをクリア テキストで保存していますが、これは非常に重大なセキュリティ エラーです。 また、文字列連結を使用して SQL を構築しているため、SQL インジェクション (Google it) によってデータベースが破壊される可能性があります。 パスワードの適切なハッシュと、SQL のパラメーター化されたクエリを常に使用する必要があります。

コメント

タイトルとURLをコピーしました