Skip to main content

Reference code for AJAX and Sweetalert

 

<?php
include('php-includes/check-login.php');
require('php-includes/connect.php');
?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Mlml Website  - Home</title>

    <!-- Bootstrap Core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href='../dist/css/style.min.css' rel='stylesheet' />

    <!-- MetisMenu CSS -->
    <link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
      <script src='https://unpkg.com/sweetalert/dist/sweetalert.min.js'></script>

  <script>
    
    function deleteCountry(a){  

        swal({
              title: "Are you sure?",
              text: "Once deleted, you will not be able to recover this!",
              icon: "warning",
              buttons: true,
              dangerMode: true,
            })
            .then((willDelete) => {
              if (willDelete) {
                window.location.href = "cntrl_location.php?delete_country="+a;
              } else {
                swal("Everything is safe now.");
              }
            });


    }

    </script>

    <script type="text/javascript">
        function editCountryDialog($a){
         $.ajax({
             url : "cntrl_location.php?editCountryDialog="+$a,
             cache : false,
             beforeSend : function (){
                  //Show a message
             },
             complete : function($response, $status){
                 if ($status != "error" && $status != "timeout") {
                     $('#editCountryLayer').html($response.responseText);
                 }
             },
             error : function ($responseObj){
                 alert("Something went wrong.\n\nError => "
                     + $responseObj.responseText);
             }
         });
        }
    </script>


</head>


<body>

    <div id="wrapper">

        <!-- Navigation -->
        <?php include('php-includes/menu.php'); ?>

        <!-- Page Content -->
        <div id="page-wrapper">
                        <div class="container-fluid">
                <!-- *************************************************************** -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Add Coutry</h4>
                                <form action="cntrl_location.php" method="POST">
                                    <div class="form-body">

                                        <div class="row">
                                            <div class="col-md-4">
                                                <label>Name </label>
                                                <div class="form-group">
                                                    <input type="text" name="country_nm" required="" class="form-control" placeholder="Enter coutry name">
                                                </div>
                                            </div>

                                            <div class="col-md-4">
                                                <label>Short name</label>
                                                <div class="form-group">
                                                    <input type="text" name="country_short" required="" class="form-control" placeholder="Enter country shortname ">
                                                </div>
                                            </div>

                                            <div class="col-md-4">
                                                <label>Marathi text</label>
                                                <div class="form-group">
                                                    <input type="text" name="country_mr" required="" class="form-control" placeholder="Enter Country in marathi">
                                                </div>
                                            </div>

                                        </div>
                                        
                                    </div>
                                    <div class="form-actions">
                                        <div class="text-right">
                                            <input type="hidden" name="add_country" value="add_country" class="btn btn-info">
                                            <button type="submit" class="btn btn-info">Submit</button>
                                            <button type="reset" class="btn btn-dark">Reset</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">Countries</h4>
                                 <div class="table-responsive">
                                    <table id="zero_config" class="table table-striped table-bordered no-wrap">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Country name</th>
                                                <th>Short name</th>
                                                <th>Marathi</th>
                                                <th>Edit</th>
                                                <th>Delete</th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                           <?php $sql = "SELECT * FROM loc_country WHERE inactive='0';";

                                            $result = $con->query($sql);

                                            $sr=1;

                                            while($row=$result->fetch_assoc()) {

                                                echo "<tr>
                                                        <td>".$sr."</td>
                                                        <td>".$row['country_name']."</td>
                                                        <td>".$row['short_name']."</td>
                                                        <td>".$row['mr_text']."</td>" ?>

                                                        <td>
                                                            <button type="button" onclick="editCountryDialog('<?php echo $row['id']?>')" class="btn btn-primary btn-sm btn-circle" data-toggle="modal" data-target="#bs-example-modal-lg"><i class='icon-pencil'></i></button>

                                                            <!-- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#bs-example-modal-lg">Standard Modal</button> -->


                                                        </td>

                                                        <td>
                                                            <button type="button" onclick="deleteCountry('<?php echo $row['id']?>')"class="btn btn-danger btn-sm btn-circle"><i class='fas fa-trash-alt'></i></button>
                                                        </td>

                                                   <?php echo "</tr>";

                                                $sr++;
 
                                            }  

                                            ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                
                <div class="modal fade" id="bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-lg modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title" id="myLargeModalLabel">Update country</h4>
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            </div>
                            <div class="modal-body" id='editCountryLayer'>
                                
                            </div>
                        </div>
                    </div>
                </div>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="vendor/jquery/jquery.min.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="vendor/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="dist/js/sb-admin-2.js"></script>

</body>

</html>
 

Comments

Popular posts from this blog

Restoring MySQL on XAMMP

  Follow these steps and save your time and databases:- Go to your  XAMMP  installation, it’s mostly in  C drive . Now inside  mysql  folder rename the folder  data  to  data-old  (or any other name you like) Create a new folder  data  under  mysql  folder Copy the contents of  backup  folder to the new  data  folder Now copy all your  database  folders that are in  data-old  folder to the new  data  folder (skip the mysql, performance_scheme and phpmyadmin folder) And the last, copy the  ibdata1  file from  data-old  folder and replace it inside new  data  folder Restart your  MYSQL  server from  XAMPP control panel . And done!

Adding image on text using php (Certificate generation in php)

      <?php header('Content-type: image/jpeg'); //loading custom form $font=realpath('arial.ttf'); //creating pointer from sample image which is being edited $image=imagecreatefromjpeg("format.jpg"); //Adding color $color=imagecolorallocate($image, 51, 51, 102); $date=date('d F, Y'); //Adding date on image imagettftext($image, 18, 0, 880, 188, $color,$font, $date); //Adding name on image $name="Sagar kokare"; imagettftext($image, 48, 0, 120, 520, $color,$font, $name); //Saving edited image on server imagejpeg($image,"$name.jpg"); // you can show this image in browser // imagejpeg($image); imagedestroy($image); ?>