How to add Sweetalert to Dreamweaver CC insert code

1. Add the insert code as seen below
<?php
if ($_SERVER[“REQUEST_METHOD”] === “POST”) {
  $InsertQuery = new WA_MySQLi_Query($TestDB);
  $InsertQuery->Action = “insert”;
  $InsertQuery->Table = “tbl_strgicwkpln”;
  $InsertQuery->bindColumn(“workplanID”, “s”, “”.((isset($_POST[“workplanID”]))?$_POST[“workplanID”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“department”, “s”, “”.((isset($_POST[“department”]))?$_POST[“department”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“quarter”, “s”, “”.((isset($_POST[“quarter”]))?$_POST[“quarter”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“objectives”, “s”, “”.((isset($_POST[“objectives”]))?$_POST[“objectives”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“goal”, “s”, “”.((isset($_POST[“goal”]))?$_POST[“goal”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“datesubmitted”, “t”, “”.((isset($_POST[“datesubmitted”]))?$_POST[“datesubmitted”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“deskofficer”, “s”, “”.((isset($_POST[“deskofficer”]))?$_POST[“deskofficer”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“supervisor”, “s”, “”.((isset($_POST[“supervisor”]))?$_POST[“supervisor”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->bindColumn(“addedby”, “s”, “”.((isset($_POST[“addedby”]))?$_POST[“addedby”]:””)  .””, “WA_DEFAULT”);
  $InsertQuery->saveInSession(“swp_id”);
  $InsertQuery->execute();
  $InsertGoTo = “addWorkPlan?success”;
  if (function_exists(“rel2abs”)) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):””;
  $InsertQuery->redirect($InsertGoTo);
}
?>
2. Next add the code below anywhere before the insert form and within the body tag
<?php
if (isset($_GET[“success”])) {
?>
<?php
echo ‘
<script>
swal({
  title: “Your Record Was Saved Successfully!”,
  text: “Redirecting in 2 seconds.”,
  type: “success”,
  timer: 2000,
  showConfirmButton: false
}, function(){
  window.location.replace(“addWorkPlan”);
});
</script>
‘;
?>
<?php
}
?>
See example:
Download and run the attached sample application. After loading the application, load this URL  http://localhost:8888/testserver/addWorkPlan

Leave a Reply

Your email address will not be published. Required fields are marked *