Blank page on submit button

此生再无相见时 提交于 2019-12-12 03:06:00

问题


I have some troubles with my html page. I want it to reload after pressing the submit button. I tried reloading it with javascript but it keeps on giving me a white page (after saving the data I need in a file).

Here is the html code:

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

here is the php code:

<?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');
}

Thanks for your help!


回答1:


I think you are missing one condition here

you have only

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

try to add the else and see

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


来源:https://stackoverflow.com/questions/40673778/blank-page-on-submit-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!