php登入系統/unity中的未定義變數問題
P粉322106755
P粉322106755 2024-03-29 21:16:04
0
1
421

我收到此錯誤:警告:第 21 行 C:\xampp\htdocs\BNP\Login.php 中未定義變數 $loginUser 使用者名稱不存在。我嘗試了其他修復,但它返回相同的錯誤訊息。有人可以幫忙嗎?

<?php

//variables for connecting to DB
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "unityaccess";

//variables submitted by user
if(isset($_POST['loginUser'])){ $loginUser = $_POST['loginUser']; }
if(isset($_POST['loginPass'])){ $loginPass = $_POST['loginPass']; }

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT password FROM users WHERE username = '" . $loginUser . "'";


$result = $conn->query($sql);

if ($result->num_rows > 0){
  // output data of each row
  while($row = $result->fetch_assoc()) {
if($row["password"] == $loginPass){
    echo "Login Success, welcome.";
}
else {
    echo "Wrong Credentials";
}
  }
} else {
  echo "Username does not exists";
}

$conn = null;



?>

謝謝

P粉322106755
P粉322106755

全部回覆(1)
P粉118698740

您的 $loginUser 未定義,還要檢查您的表單名稱屬性是否有“loginUser”,並使用此更新的程式碼,我在其中定義了 $loginUser ,它將起作用。

connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    
    $sql = "SELECT password FROM users WHERE username = '" . $loginUser . "'";
    
    
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0){
      // output data of each row
      while($row = $result->fetch_assoc()) {
    if($row["password"] == $loginPass){
        echo "Login Success, welcome.";
    }
    else {
        echo "Wrong Credentials";
    }
      }
    } else {
      echo "Username does not exists";
    }
    
    $conn = null;
    
    
    
    ?>
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板