Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - notify me when data inserted in database php

if (($address == "") AND ( $date == "")) {
  echo "";
} else {
  date_default_timezone_set('Etc/GMT+8');
  $sent_dt = date('Y-m-d H:i:s');

  $sql = "INSERT INTO info (address,date) VALUES (:phone,:date)";
  $q = $CNT->prepare($sql);
  $q->execute(
    array(
      ':address' => "$address",
      ':date' => "$sent_dt"
    )
  );
}

I want to put this script inside else so that every time there is a new data inserted it will notify me.

echo'<script>
    Push.create("Hello from the other side!", {
    body: "You're invited",
    icon: "img/k.jpg",
    timeout: 4000,
    onClick: function () {
        window.focus();
        this.close();
    }
  });
</script>';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check if the statement execute returns true or false:

if($q->execute(array(':address'=>"$address",':date'=>"$sent_dt"))==TRUE) {
       echo ' <script>Push.create("Hello from the other side!", { body: "You're invited", icon: "img/k.jpg", timeout: 4000, onClick: function () { window.focus(); this.close(); }`` });</script> '; 
  }

Oh by the way we have to escape characters...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...