🔒 Closed Pano gamitin tong SweetAlert sa PHP ?.. Pasok mga Tropa!!

Status
Not open for further replies.

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 :love:
PHC - Naethan
 
echo "<script type='text/javascript'>
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);

</script>";

<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
 
echo "<script type='text/javascript'>
Swal.fire(
'There You Go!',
'New-Record added, Successfully!',
'success'
);

</script>";

<script src="You do not have permission to view the full content of this post. Log in or register now."></script>
Tinry ko na to tol, nababasa kaso di nag didisplay ewan ko ba

Nilagay ko narin to sa <head> <script src="You do not have permission to view the full content of this post. Log in or register now."></script>

Tignan mo pattern ng code ko
 
etong sweetalert cdn gamitin mu

PHP:
<?php
echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.6.15/dist/sweetalert2.all.min.js"></script>';

echo '<script type="text/javascript">
Swal.fire(
  "There You Go!",
  "New-Record added, Successfully!",
  "success");</script>';
?>

pag no error pero wala pa rin yung alert. ilipat mo yung full php code mo sa loob ng <body> bago mag </body>.


PHP:
<html
<head>
</head>
<body>
// all html codes here
    
<?php
// php codes here
// all php code that echo javascript codes should be placed in the body
?>
</body>
</html>
 
Tinatry daw niyang paganahin sa php

Try mo muna kung gumagana yang sweetalert mo sa javascript, baka mamaya pati sa javascript hindi pala gumagana?
Oks yung javascript kumpleto, kinuha ko mismo yung file nila then naka save na as .js
Tataawagin nalng..
 
Oks yung javascript kumpleto, kinuha ko mismo yung file nila then naka save na as .js
Tataawagin nalng..
Working ba yung query mo paps? Try mo walang script yung echo. Im also working with my web system gamit ajax at php, nagkaproblema din ako nyan dati.
 
etong sweetalert cdn gamitin mu

PHP:
<?php
echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.6.15/dist/sweetalert2.all.min.js"></script>';

echo '<script type="text/javascript">
Swal.fire(
  "There You Go!",
  "New-Record added, Successfully!",
  "success");</script>';
?>

pag no error pero wala pa rin yung alert. ilipat mo yung full php code mo sa loob ng <body> bago mag </body>.


PHP:
<html
<head>
</head>
<body>
// all html codes here
   
<?php
// php codes here
// all php code that echo javascript codes should be placed in the body
?>
</body>
</html>

Working ba yung query mo paps? Try mo walang script yung echo. Im also working with my web system gamit ajax at php, nagkaproblema din ako nyan dati.

OKs na load method 2 Working, tae na kase.. yun nilagay sa tutorial ng admin Form ehh.. Sorry bata pa sa PHP mga kosa
 
Status
Not open for further replies.

About this Thread

  • 12
    Replies
  • 1K
    Views
  • 7
    Participants
Last reply from:
V01D_

Online now

Members online
616
Guests online
647
Total visitors
1,263

Forum statistics

Threads
2,276,935
Posts
28,973,174
Members
1,230,625
Latest member
heyuhe
Back
Top