我有使用MVC模式的登錄系統,雖然它仍然是程序性的,並且已經過了4個小時,並且不能工作。它繼續執行最後一個'else'語句,該語句被重定向回login.php。這是我的代碼登錄頁面無法繼續請求?
登錄頁面:
<?php include 'view/template/header.php' ?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<div class="login-style">
<h2>Silahkan Login</h2>
<form action="controller/controller-login-admin.php" method="POST">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" name="username" class="form-control" id="username">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" name="password" class="form-control" id="pwd">
</div>
<button type="submit" name="submit-admin-login" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
<?php include 'view/template/footer.php' ?>
控制器
<?php
require_once $_SERVER['DOCUMENT_ROOT']. '/project-school-frontend/admin/model/admin-model-master.php';
if (isset($_POST['submit-admin-login'])){
$username=mysqli_real_escape_string($koneksi, $_POST['username']);
$password=mysqli_real_escape_string($koneksi, md5($_POST['password']));
loginUser($username, $password);
}
(控制器正常工作)
型號:
<?php
require_once $_SERVER['DOCUMENT_ROOT']. '/project-school-frontend/config/database.php';
function loginUser($username, $password){
global $koneksi;
if (empty($username) && !empty($password))
{
$_SESSION['pesan'] = 'Userid harus diisi';
$_SESSION['alert'] = 'info';
header('location:../login.php');
}
elseif (empty($password) && !empty($username))
{
$_SESSION['pesan'] = 'Password harus diisi';
$_SESSION['alert'] = 'info';
header('location:../login.php');
}
elseif (empty($username && $password))
{
$_SESSION['pesan'] = 'Userid dan password wajib diisi';
$_SESSION['alert'] = 'info';
header('location:../login.php');
}
else
{
$sql= "SELECT * FROM admin WHERE username='$username' AND password='$password'";
$query= mysqli_query($koneksi, $sql);
$result= mysqli_num_rows($query);
$row = mysqli_fetch_array($query);
if($result > 0)
{
session_start();
$_SESSION['username']=$row['username'];
$_SESSION['level'] = $row['level'];
header('Location: ../view/admin-dashboard.php');
}
else
{
header('Location: ../login.php');
}
}
}
(這是怎麼開始的。該型號)
我該怎麼辦?
試試這個'$查詢= mysqli_query($ koneksi,$ SQL)或死亡(mysqli_error(koneksi $));' – JYoThI
非常感謝你的回覆。非常感激。無論如何,它不起作用。我的登錄頁面仍然沒有通過。沒有消息,但重定向到登錄頁面再次 – mending3
試試這個'$ row = mysqli_fetch_array($ query);的print_r($行);退出;' – JYoThI