php登录系统/unity中的未定义变量问题
P粉322106755
P粉322106755 2024-03-29 21:16:04
0
1
410

我收到此错误:警告:第 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;
    
    
    
    ?>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板