脚本标签无法在php

时间:2017-06-16 09:24:08

标签: javascript php sweetalert

我希望在单击buttn数据库查询成功后显示甜蜜警报弹出窗口。当我把甜蜜警报脚本标签放在PHP代码中我不起作用

<?php 

   error_reporting(E_ALL);
include ('includes/database.php');

if(isset($_POST['cmptbtn']))
     {

                              $cmpltxt = $_POST['cmpltxt'];
                              $checkbox = $_POST['cmplt'];
                              // $chkb ="";
   $sqlchkb = $conn->query("INSERT INTO complaint (complaint_type, complaint_comm) VALUES ('$checkbox', '$cmpltxt')");

                              // $sql = $conn->query("INSERT INTO complaint (complaint_comm) VALUES ('$cmpltxt')");

                              }
                              if ($sqlchkb === true){

                                echo "<script type="text/javascript">

                                    document.querySelector('.btnsnd').onclick = function(){
                                    swal("Good job!", "You clicked the button!", "success");
                                  };

                                  </script>";

                              }else{

                                echo "sorry try again";


                                }


                             $conn->close();


                       ?>

2 个答案:

答案 0 :(得分:0)

你有"的回声开始和结束,并且你也可以{echo = {1}}回复你,这样尝试"

'

我希望它能奏效。我知道。

答案 1 :(得分:0)

的error_reporting(E_ALL); include(&#39; includes / database.php&#39;);

如果(isset($ _ POST [&#39; cmptbtn&#39;]))      {

                          $cmpltxt = $_POST['cmpltxt'];
                          $checkbox = $_POST['cmplt'];
                          // $chkb ="";


                          $sqlchkb = $conn->query("INSERT INTO complaint (complaint_type, complaint_comm) VALUES ('$checkbox', '$cmpltxt')");

                          }
                          if ($sqlchkb === true){

                            ?><script type="text/javascript">

                                document.querySelector('.btnsnd').onclick = function abc(){
                                swal("Good job!", "You clicked the button!", "success");
                              };

                              </script><?php

                          }else{

                            echo "sorry try again";


                            }


                         $conn->close();


                   ?>

试试这个