简体   繁体   English

成功提交表单后如何重定向页面PHP头不起作用

[英]How To Redirect The Page After Successfull Form Submission PHP Header is not working

Here is my code to register a user.when i click on signup the url in header function is not generated with passing variable success.it just shows The upper section of form header 这是我注册用户的代码。当我单击注册时,标头函数中的url不会通过传递变量成功生成。它仅显示表单标头的上部

<?php
    if(isset($_GET['success']) && empty($_GET['success'])){

        $msg= "You Have Been Registered!";
        echo $msg;
        }
    else{
        if(empty($_POST) === false && empty($errors) === true){
        $register_data = array(
            'user_name' => $_POST['username'],
            'password' => $_POST['pass'],
            'email' => $_POST['email'],
            'mobileno' => $_POST['cell'],
            'gen' => $_POST['gen'],
            'first_name' => $_POST['firstname'],
            'last_name' => $_POST['lastname']
        );
        register_user($register_data);
        echo "redirecting to";
        header("location:../../core/Admin/registrationform.php?success");
            exit();
        }else if(empty($errors) === false ){
            echo output_errors($errors);
        }

    }
        ?>


    </div>
  <form  method="post" action="">

            <label>First Name*</label> <input type="text" name="firstname"/> 
            <label>Last Name</label> <input type="text" name="lastname"/>  
            <label>Gender*</label> <input type="text" name="gen"/>  
            <label>User Name*</label> <input type="text" name="username"/> 
            <label>Email*</label> <input type="text" name="email"/>
            <label>Mobile No* (Must Be Given)</label> <input type="text" name="cell"/>  
            <label>Password*</label> <input type="text" name="pass"/>  
            <label>Confirm Password*</label> <input type="text" name="confirmpass"/>
             <label>Write The Answer Of* :</label> <input type="text" name="ans"/> 
            <input id="resetbutton" type="reset" value="Reset Fields"/>
            <input id="submitbutton" type="submit" name="submit" value="Sign Up"/>  
        </form>

Try below code: 试试以下代码:

header('Location: url..?success=1');

Call full url in header function 在标头函数中调用完整网址

or 要么

Use jQuery function to redirect to a page 使用jQuery函数重定向到页面

window.location 

http://www.w3schools.com/js/js_window_location.asp http://www.w3schools.com/js/js_window_location.asp

refer this link 请参阅此链接

有技巧,在<?php之后的第一行中使用ob_start()

Always remember if you are going to redirect to any page then you should not print anything before that otherwise you will get error something like header already sent....just remove 永远记住,如果您要重定向到任何页面,那么在此之前您不应该打印任何内容,否则会出现类似已发送标题的错误。

 echo "redirecting to";

before header function 标头功能之前

check this code 检查此代码

<?php
    if(isset($_GET['success']) && empty($_GET['success'])){

        $msg= "You Have Been Registered!";
        echo $msg;
        }
    else{
        if(empty($_POST) === false && empty($errors) === true){
        $register_data = array(
            'user_name' => $_POST['username'],
            'password' => $_POST['pass'],
            'email' => $_POST['email'],
            'mobileno' => $_POST['cell'],
            'gen' => $_POST['gen'],
            'first_name' => $_POST['firstname'],
            'last_name' => $_POST['lastname']
        );
        register_user($register_data);

        header("location:../../core/Admin/registrationform.php?success");
            exit();
        }else if(empty($errors) === false ){
            echo output_errors($errors);
        }

    }
        ?>


    </div>
  <form  method="post" action="">

            <label>First Name*</label> <input type="text" name="firstname"/> 
            <label>Last Name</label> <input type="text" name="lastname"/>  
            <label>Gender*</label> <input type="text" name="gen"/>  
            <label>User Name*</label> <input type="text" name="username"/> 
            <label>Email*</label> <input type="text" name="email"/>
            <label>Mobile No* (Must Be Given)</label> <input type="text" name="cell"/>  
            <label>Password*</label> <input type="text" name="pass"/>  
            <label>Confirm Password*</label> <input type="text" name="confirmpass"/>
             <label>Write The Answer Of* :</label> <input type="text" name="ans"/> 
            <input id="resetbutton" type="reset" value="Reset Fields"/>
            <input id="submitbutton" type="submit" name="submit" value="Sign Up"/>  
        </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM