数据插入数据库php时通知我

时间:2017-07-01 13:13:40

标签: javascript php database

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"
    )
  );
}

我想将此脚本放在其他内容中,以便每次插入新数据时都会通知我。

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>';

1 个答案:

答案 0 :(得分:1)

检查语句execute是返回true还是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> '; 
  }

哦,顺便说一句,我们必须逃避角色...