2012-06-21 27 views
-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"); 
} 


      } 

但它不是任何地方重定向,但其成功提交該數據。請給我建議我要去的地方錯了。

+0

你的SQL是不是很安全,你一定要研究SQL注入,以及如何避免它 – jopke

+0

無論你得到任何錯誤或警告添加error_reporting(E_ALL);在代碼的頂部,並嘗試 –

+0

這段代碼有太多的錯誤。 Sql注入,錯誤suppersion,舊的mysql_ *函數....不要使用@GET。用isset說至少。你不應該吃錯誤,你應該解決它們。 – itachi

回答

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> 
+0

非常感謝。這對我有效。非常感謝。 – user1321271

0

你可以做到這樣,通過包括本在開始:

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

希望這有助於! :)

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; 
?> 
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 --> 
相關問題