-1

在成功将用户信息提交到数据库后,我想将用户重定向到下一页。我正在使用这样的重定向功能

<?php
    $plan = @$_GET['plan']; // this is from url

?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"  onsubmit="return Validate();">
                <input type="hidden" name="plan" value="<?php echo $plan ?>"/>
    Company Name: 
        <input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br />
    Company E-mail : 
    <input type="text" name="CompanyEmail" style="width:230px; height:20px;" /><br /><br />
     Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br />
     Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br />
    Select Your Registration Type : <br /><br />
Trail: <input type="radio" name="RegistrationType" value="Trail" /><br />
                                     Paid<input type="radio" name="RegistrationType" value="Paid" /><br /><br />

     <input type="hidden" name="form_submitted" value="1"/> 
     <input type="submit" value="REGISTER" name="submit" />



</form> 
 <?php

     include('connect.php');

            If (isset($_POST['submit']))
            {
            $CompanyName = $_POST['CompanyName'];

            $CompanyEmail = $_POST['CompanyEmail'];
            $CompanyContact = $_POST['CompanyContact'];
            $CompanyAddress = $_POST['CompanyAddress']; 

            $RegistrationType = $_POST['RegistrationType'];
            $Plans = $_POST['plan'];
            $Status = "Active";


    $sql = "INSERT INTO ApplicationRegister (CompanyName, CompanyEmail, CompanyContact, CompanyAddress, RegistrationType, ApplicationPlan, ApplicationStatus, CreatedDate) VALUES ('$CompanyName', '$CompanyEmail', '$CompanyContact', '$CompanyAddress', '$RegistrationType', '$Plans', '$Status', NOW() )";
$result = mysql_query($sql) or die(mysql_error());

if($plan == "trail")
{

header("Location: userRegister.php");
}
else
{
    header("Location : PaymentGateway.php");
}


            }

但它没有重定向到任何地方,但它成功提交了数据。请告诉我我哪里出错了。

4

4 回答 4

1

header()将任何内容发送到浏览器后,您将无法使用。在这种情况下,您在中间的所有 HTML 都将首先发送。将所有 PHP 移动到文件顶部应该意味着它可以工作 - 额外的好处是更易于阅读!

<?php
$plan = @$_GET['plan']; // this is from url
include('connect.php');

if (isset($_POST['submit'])) {
    $CompanyName = $_POST['CompanyName'];

    $CompanyEmail = $_POST['CompanyEmail'];
    $CompanyContact = $_POST['CompanyContact'];
    $CompanyAddress = $_POST['CompanyAddress'];

    $RegistrationType = $_POST['RegistrationType'];
    $Plans = $_POST['plan'];
    $Status = "Active";


    $sql = "INSERT INTO ApplicationRegister 
    CompanyName, CompanyEmail, CompanyContact, CompanyAddress, RegistrationType, ApplicationPlan, ApplicationStatus, CreatedDate) 
    VALUES 
    ('$CompanyName', '$CompanyEmail', '$CompanyContact', '$CompanyAddress', '$RegistrationType', '$Plans', '$Status', NOW() )";

    $result = mysql_query($sql) or die(mysql_error());

    if ($plan == "trail") {
        header("Location: userRegister.php");
        exit();
    } else {
        header("Location : PaymentGateway.php");
        exit();
    }
}
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1"  onsubmit="return Validate();">
    <input type="hidden" name="plan" value="<?php echo $plan ?>"/>
    Company Name: 
    <input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br />
    Company E-mail : 
    <input type="text" name="CompanyEmail" style="width:230px; height:20px;" /><br /><br />
    Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br />
    Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br />
    Select Your Registration Type : <br /><br />
    Trail: <input type="radio" name="RegistrationType" value="Trail" /><br />
    Paid<input type="radio" name="RegistrationType" value="Paid" /><br /><br />

    <input type="hidden" name="form_submitted" value="1"/> 
    <input type="submit" value="REGISTER" name="submit" />
</form> 
于 2012-06-21T05:38:50.470 回答
0

您可以通过在开头包含以下内容来执行此操作:

<?php
    if(mysql_query($query))
        header('Location: http://example.com/newurl/');
    else
        echo "Error!";
?>

希望这可以帮助!:)

于 2012-06-21T05:29:01.423 回答
0

只是为了一个约定,养成exit在你的header().

<?php
header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>
于 2012-06-21T05:33:43.027 回答
0

只放置您要重定向的页面路径:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
                                ADD CONTENT
                            </button>
                            <!-- Modal -->
                            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                            <h4 class="modal-title" id="myModalLabel">Please Add Content</h4>
                                        </div>
                                        <div class="modal-body">
                <form role="form" action="" method="POST">
      <!-- YOUR HTML FORM GOES HERE--->
<button type="submit" name="submit" class="btn btn-primary btn-lg"id="sub" onclick="SUBMISSION()" >Submit </button>
                            </fieldset>

             </form>
  <?php
if(isset($_POST['submit']))
{

    SUBMISSION();
    }
function SUBMISSION()
{
 // UR CONNECTION ESTABLISHMENT CODE GOES HERE
  // SQL QUERY FOR INSERTION IN FIELDS

 echo"<script type=\"text/javascript\">
document.location.href='http://localhost/your file path/YOURPAGE.php'; // ur desired redirect page path where u want to go with recent submit data u can also in same page
</script>";

$conn->CLOSE();

}

?>

                                        </div>

                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal-dialog -->


                            <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->  
于 2015-07-31T10:27:10.997 回答