0

我有一个注册表格enroll.php,它提交给自己,如果所有输入都有效,它包括confirm.php,我必须将数据保存到表中。

看起来像这样 -

注册.php

  <?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    include('validate.php');

    if($valid) {
        require_once ('getDBconnection.php');        
        include ('confirm.php'); 
    }
}
function test_input($data) {
         $data = trim($data);
         $data = stripslashes($data);
         $data = htmlspecialchars($data);
         return $data;
    }
?>
<!DOCTYPE html >
<html>
// all html code with banner and navigation and form elements.

因此,当我在确认文本后在整个页面下方获得注册确认时,我会看到我的表单,其中包含所有横幅和导航以及所有 div 内容和表单。

是因为我包含了confirm.php吗?

如果有什么问题,请告诉我我刚刚开始学习 php。

4

4 回答 4

0

尝试在 indlude confirm.php 之后添加退出以停止使用菜单等执行整个站点。

if($valid) {
    require_once ('getDBconnection.php');        
    include ('confirm.php'); 
    exit();
}
于 2013-10-31T06:40:16.360 回答
0

您应该重定向到confirm.php,而不是包含它

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    include('validate.php');

    if($valid) {
        header('Location: confirm.php'); 
    }
}
function test_input($data) {
         $data = trim($data);
         $data = stripslashes($data);
         $data = htmlspecialchars($data);
         return $data;
    }
?>



<!DOCTYPE html >
<html>
// all html code with banner and navigation and form elements.

编辑

当然,这仅在您尚未向浏览器输出任何内容时才有效(IE echo 'Please fill out the form correctly';:)

于 2013-10-31T06:40:44.843 回答
0

Its because enroll.php runs to the end of the file regardless if confirm.php is included or not.

You should most likly submit the form to confirm.php, and then redirect the user in confirm.php

于 2013-10-31T06:40:52.020 回答
0

You can either redirect the page to confirm.php or If you want to include confirm.php than you need to put exit() or die() after the line include ('confirm.php');

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    include('validate.php');

    if($valid) {
        require_once ('getDBconnection.php');        
        include ('confirm.php'); 
        exit(); //or you can also use die();
    }
}
function test_input($data) {
         $data = trim($data);
         $data = stripslashes($data);
         $data = htmlspecialchars($data);
         return $data;
    }
?>
于 2013-10-31T06:48:17.867 回答