douzhouhan4618 2014-07-29 10:04
浏览 29
已采纳

使用php提交表单提交的警报框

Alert box is not working at the time of submitting the form. Nevertheless, I get 'Customer Added Successfully' message in php. But I don't get an alert box. My code is given below:

   if($_POST['submit']) 
    { 
       $name=$_POST['name'];
       $phone_number=$_POST['phone_number'];
       $email=$_POST['email'];
       $sql="insert into
       customer set    name='$name',phone_number='$phone_number',email='$email'";
       $in executeUpdate($sql);
       if($in)
        {
         echo "<script type=\"text/javascript\">".
         "alert('success');".
         "</script>";
          $sess_msg="Customer Added Successfully.";
          $_SESSION['sess_msg']=$sess_msg;

        }
      header("Location: addCustomer.php");
    }
  • 写回答

1条回答 默认 最新

  • dpeqsfx5186 2014-07-29 10:09
    关注

    You're sending a Location: header which results in a redirect, so the browser ignores any code in the page (including the javascript containing the alert).

    You either need to remove the redirect (display the alert and a link to the next page), or display the alert on the target of the redirect. I'd go for the second option to avoid issues with reloads on a POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题