提交按钮上的空白页

时间:2016-11-18 09:44:21

标签: php html reload

我的html页面有些麻烦。我希望在按下提交按钮后重新加载。我尝试用javascript重新加载它,但它继续给我一个白页(在保存文件中我需要的数据后)。

这是html代码:

<html>
    <head>
        <title>Sample Web Form</title>
    </head>
<body>

<h1>Fill Out This Form</h1>


<form action="myprocessingscript.php" method="POST">
<p><i>Choose one or more of the available options that represent the current mental state of the System:</i></p>
  <input type="checkbox" name="mentalState[]" value="Knows user culture"> Knows User Culture<br>
  <input type="checkbox" name="mentalState[]" value="Knows concept "> Knows Concept<br>
    <input type="checkbox" name="mentalState[]" value="Knows that user knows concept"> Knows that User Knows Concept<br>


<p><i>Choose the corresponding action:</i></p>
  <input type="checkbox" name="action" value="cultureIdentif"> Culture Identification<br>
  <input type="checkbox" name="action" value="conceptIdentif"> Concept Identification<br>


<p><i>Choose one or more of the available options that represent the current mental state of the System following the action:</i></p>

  <input type="checkbox" name="mentalState2[]" value="Knows user culture"> Knows User Culture<br>
  <input type="checkbox" name="mentalState2[]" value="Knows concept"> Knows Concept<br>
    <input type="checkbox" name="mentalState2[]" value="Knows that user knows concept"> Knows that User Knows Concept<br>
  </br>

  <input type="submit" value="Save Data">

</form>
</body>
</html>

这是php代码:

<?php


if(!empty($_POST['mentalState'])){
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['mentalState'] as $mentalState)
        ($mentalState1=$mentalState . ',' . $mentalState1);
    }

    if(!empty($_POST['mentalState2'])){
        // Loop to store and display values of individual checked checkbox.
        foreach($_POST['mentalState2'] as $mentalState)
            ($mentalState2=$mentalState . ',' . $mentalState2);
        }


        if(isset($mentalState1) && isset($_POST['action']) && isset($mentalState2)) {
            $data = $mentalState1 . '-' . $_POST['action'] . '-' . $mentalState2 . "\n";
            $ret = file_put_contents('matrix.txt', $data, FILE_APPEND | LOCK_EX);
            if($ret === false) {
                die('There was an error writing this file');
            }

    } else {
   die('no post data to process');
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我认为你在这里缺少一个条件

你只有

if($ret === false) {
    die('There was an error writing this file');
}

尝试添加其他内容并查看

if($ret === false) {
    die('There was an error writing this file');
} else {
  header('Location: ' . $_SERVER['HTTP_REFERER']);
}