douzhuan4406 2016-01-22 05:07
浏览 85
已采纳

警告不会在php中弹出

In a particular php file iam using a header and an alert box before it executes header, but its neglecting alert and executing header directly..!!please help me resolving this...!!pardon if i went wrong somewere. .php

<?php
header('location: formprofile.php');
session_start();
        require_once 'DB_Functions.php';
        $db = new DB_Functions();

        // json response array
        $response = array("error" => false);
        if (!empty($_POST['salutation']) && !empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['dob']) && !empty($_POST['mobile']) && !empty($_POST['country']) && !empty($_POST['state']) && !empty($_POST['city']) && !empty($_POST['pin'])){
                /*
                if required include seperate validation
                for some fields which require validation
                */
                // receiving the post params
                $salutation = ($_POST['salutation']);
                $fname = trim($_POST['fname']);
                $lname = trim($_POST['lname']);
                $dob = trim($_POST['dob']);
                $mobile = trim($_POST['mobile']);
                $country = trim($_POST['country']);
                $state = trim($_POST['state']);
                $city = trim($_POST['city']);
                $pin = trim($_POST['pin']);

                /*
                validation process
                starts from here
                */

                // validate your email address
               if(strlen($mobile) == 10){

                  if($db->isMobileNumberExisted($mobile)) {
                         //user already existed
                         $response["error"] = true;
                         $response["error_msg"] = "user already existed with" . $mobile;
                         echo json_encode($response);
                   }else{  
                           // create a new user
                           $user = $db->storeUser($salutation, $fname, $lname, $dob, $mobile, $country, $state, $city, $pin);
                           if ($user) {
                               // user stored successfully
                               $response["error"] = false;
                               $_SESSION['fullname'] = $user['fullname'];
                               $_SESSION['vault_no'] = $user['vault_no'];
                                                                        $message = "Registration successful";
                               echo "<script type='text/javascript'>alert('$message');</script>";

                             } else {
                                // user failed to store
                                $response["error"] = true;
                                $response["error_msg"] = "Unknown error occurred in registration!";
                                echo json_encode($response);
                             }
                       }

                }else{
                        //invalid mobile number
                        $response["error"] = true;
                        $response["error_msg"] = "PLEASE ENTER VALID MOBILE NUMBER!";
                        echo json_encode($response);
                    }

        }else{
               //missing the required fields
                $response["error"] = true;
                $response["error_msg"] = "Please fill all the required parameters!";
                echo json_encode($response);
          }

?>  
  • 写回答

1条回答 默认 最新

  • dongyong6045 2016-01-22 05:12
    关注
    header('location: formprofile.php');
    

    This line is redirecting the page to formprofile.php and that causes to ignore everything below it. Just remove that line or if you want redirect after execution, then move it to the end of the file and do not echo or print anything before it.

    But if you want to have some alert before redirecting to other page don't use header() for redirect. Add this JavaScript at the end of the file.

    ?>
    <script>
        alert("your message");
        document.location = "formprofile.php";
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装