Rumah > Soal Jawab > teks badan
Saya mendapat ralat ini: Amaran: Pembolehubah tidak ditentukan $loginUser dalam C:xampphtdocsBNPLogin.php pada baris 21 Nama pengguna tidak wujud. Saya mencuba pembaikan lain tetapi ia mengembalikan mesej ralat yang sama. Ada sesiapa boleh tolong?
<?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; ?>
Terima kasih
P粉1186987402024-03-30 20:33:44
$loginUser anda tidak ditakrifkan, semak juga sama ada atribut nama borang anda mempunyai "loginUser" dan gunakan kod yang dikemas kini ini di mana saya telah menentukan $loginUser dan ia akan berfungsi.
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; ?>