Мой предыдущий вопрос
После вышеупомянутого вопроса я попробовал предложение в здесь . Но модал не будет прятаться с первой попытки, поэтому мне нужно дважды ввести представление, чтобы оно заработало. Вот модальный код:
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Sign in</h5>
</div>
<div class="modal-body">
<form action="tabel_mahasiswa.php" method="post" id="login-form">
<div class="form-group">
<label for="email">Email</label>
<input type="text" id="email" name="email" class="form-control" placeholder="Masukkan Email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" class="form-control"
placeholder="Masukkan Password">
</div>
<div id="msg" style="color: red;"></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-block" id="button" value="loginSubmit">Sign In</button>
</div>
</form>
</div>
</div>
</div>
, а вот код PHP ниже:
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'];
$salt;
$get_salt = "SELECT * FROM `user` WHERE email='$email'";
$get_salt_res = $conn->query($get_salt);
while ($row = $get_salt_res->fetch()) {
$salt = $row['salt'];
}
$password = md5($_POST['password'] . $salt);
$stmt = "SELECT COUNT(*) FROM `user` WHERE email='$email' AND pass='$password'";
$res = $conn->query($stmt);
$number_of_rows = (int)$res->fetchColumn();
if ($number_of_rows == 1)
echo "<script>
$('#login-form').submit(function(e) {
e.preventDefault();
$('#loginModal').modal('hide');
return false;
});
</script>";
else
echo "<script>document.getElementById('msg').innerHTML='Email tidak terdaftar atau password salah, silakan coba lagi'</script>";
}
?>
Может кто-нибудь объяснить, почему это происходит? Я перепробовал все решения, но ни одно не помогло Любая подсказка будет оценена.
РЕДАКТИРОВАТЬ: Вот полный код:
<!DOCTYPE html>
<html>
<head>
<title> Tugas Pendahuluan</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="//cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
</head>
<body>
<!-- Modal -->
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Sign in</h5>
</div>
<div class="modal-body">
<form action="tabel_mahasiswa.php" method="post" id="login-form">
<div class="form-group">
<label for="email">Email</label>
<input type="text" id="email" name="email" class="form-control" placeholder="Masukkan Email">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" class="form-control"
placeholder="Masukkan Password">
</div>
<div id="msg" style="color: red;"></div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary btn-block" id="button" value="loginSubmit">Sign In</button>
</div>
</form>
</div>
</div>
</div>
<div class="container">
<header>
<nav class="navbar navbar-dark bg-primary mb-3">
<div class="container">
<div class="navbar-header">
<h4 style="color: white;"> [IF635] Web Programming </h4>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="navbar-right active"><a href="#">Student</a></li>
</ul>
</div>
</nav>
</header>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<button onclick="window.location.href='tambah_mhs.php'" class="btn btn-primary" style="float: right">Tambah
Mahasiswa
</button>
</div>
</div>
<table class="table" id="example">
<thead>
<tr>
<th>#</th>
<th>Student ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include_once("db_config.php");
$i = 1;
$query = "SELECT * FROM `data_mhs`";
$result = $conn->query($query);
while ($row = $result->fetch()) {
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $row['student_id'] . "</td>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "<td><a href='hapus_mhs.php?id=$row[id] '>Hapus</a> | <a href='edit_mhs.php?id=$row[id]'>Edit</a> </td>";
echo "</tr>";
$i++;
}
?>
</tbody>
</table>
</div>
<script>
$(document).ready(function (event) {
$('#example').DataTable();
$('#loginModal').modal('show');
return false;
});
</script>
</body>
</html>
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'];
$salt;
$get_salt = "SELECT * FROM `user` WHERE email='$email'";
$get_salt_res = $conn->query($get_salt);
while ($row = $get_salt_res->fetch()) {
$salt = $row['salt'];
}
$password = md5($_POST['password'] . $salt);
$stmt = "SELECT COUNT(*) FROM `user` WHERE email='$email' AND pass='$password'";
$res = $conn->query($stmt);
$number_of_rows = (int)$res->fetchColumn();
if ($number_of_rows == 1)
echo "<script>
$('#login-form').submit(function(e) {
e.preventDefault();
$('#loginModal').modal('hide');
return false;
});
</script>";
else
echo "<script>document.getElementById('msg').innerHTML='Email tidak terdaftar atau password salah, silakan coba lagi'</script>";
}
?>