PHC - Naethan
Forum Expert
Goog Evening mga ka PHC
Ask ko lng sana pano gamitin tong SweetAlert sa PHP, Tinry ko tong
PHP:
//echo "wrong username or password!";
echo "<script type="text/javascript">
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);";
Tsaka etong
//echo "wrong username or password!";
echo "<script language = javascript>
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);";
[+]Gusto ko lng naman lumabas to pag na met niya yung mga condition kaso PHP to, sa Java-script lng siya gumagana ehh..
####################################
[+]Eto yung whole code ko sa pinaka index, log in form lng naman to
PHP:
<!----PHP_TO_CHECK_FOR_USERS_EXISTANCE---->
<?php
session_start();
// Hiwalay na function tong dalawang include ignore niyo nalng
include("connection.php");
include("functions.php");
// Dito na yung mga condtion
if($_SERVER['REQUEST_METHOD'] == "POST")
{
//something was posted
$user_name = $_POST['user_name'];
$password = $_POST['password'];
if(!empty($user_name) && !empty($password) && !is_numeric($user_name))
{
//read from database
$query = "select * from users where user_name = '$user_name' limit 1";
$result = mysqli_query($con, $query);
if($result)
{
if($result && mysqli_num_rows($result) > 0)
{
$user_data = mysqli_fetch_assoc($result);
if($user_data['password'] === $password)
{
$_SESSION['user_id'] = $user_data['user_id'];
sleep(3);
header("Location: home.php");
die;
}
}
}
##Etong echo wrong password, gagana gusto ko sanang palitan ng sweet alert nalng
//echo "wrong username or password!";
echo "<script type="text/javascript">
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);";
}else
{
//echo "wrong username or password!";
echo "<script type="text/javascript">
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);";
}
}
?>
<!------------HTML_AREA------------->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="sweetalert2.all.js"></script>
<title>LOG IN</title>
</head>
<body>
<h1 class="title">ONLINE RESOURCE SYSTEM: DIGITAL LIBRARY <br>FOR BSU STUDENT IN SARMIENTO CAMPUS</h1>
<div class="center">
<img src="logo_png.png" width="100px" height="100px">
<h1>Sign In</h1>
<form method="post">
<div class="txt_field">
<input type="text" name="user_name" required>
<label>Username</label>
</div>
<div class="txt_field">
<input type="password" name="password" required>
<label>Password</label>
</div>
<input type="submit" value="Login">
<div class="signup_link">
Not registered? <a href="register.php">Sign up</a>
</div>
</form>
</div>
</body>
</html>
~ Thanks in advanced mga ka PHC

PHC - Naethan