2016-09-30 113 views
0

我正在处理一个php代码,我在窗口值和一个文件到页面呼应。我有这个工作正常,但我想实现一个按钮时重新启动按钮将再次显示该页面没有回声。任何建议或更好的方法来做到这一点?刷新页面与Php

<html> 
<head> 

</head> 
<body> 
<div class="page"> 
    <h1>File Loader</h1> 
    <form method="post"> 
     <label>Name:</label><input type="text" name="name"></br> 

     <label>Date:</label><input type="text" name="date"></br> 

     <input type="submit" name="submit" value="Submit"> 
     <input type="button" name="startOver" value="Start Over" onclick="phpfile.php"></br> 
    </form> 
</div> 

<?php 
if ($_POST['submit']) { 

    $name = $_POST['name']; 
    $date = $_POST['date']; 

    echo "Name: $name</br></br>"; 
    echo "Date: $date</br>"; 

    $file_handle = fopen("file.csv", "r"); 


     while (!feof($file_handle)) { 

      $fields_of_text = fgetcsv($file_handle, 2024); 

      $f = $fields_of_text; 
      $format = "%s %s %s %s %s %s %s %s %s %s %s"; 
      echo "<br>" . sprintf($format, $f[0], $f[1], $f[2], $f[3], $f[4], $f[5], $f[6], $f[7], $f[8], $f[9], $f[10]); 

      echo "<br>"; 

      echo "<br>"; 
      echo "<br>"; 
     } 

     fclose($file_handle); 


} else { 
    header("Location: phpfile.php"); 
} 
?> 
</div> 
</body> 
</html> 
+0

你是说这段代码不起作用吗? – nogad

+0

我不知道如何重新启动按钮来重新加载页面URL。 – user320522

+0

对于PHP你会使用'header(“Location:'但你似乎想要一个JS解决方案? – nogad

回答

0

你可以很容易地使用查询字符串/后params。

您可以像下面一样使用$ _GET,或者您可以使用隐藏的输入,并使用onclick和javascript将其更改为1或2,如果您需要使用post。

</head> 
<body> 
<div class="page"> 
    <h1>File Loader</h1> 
    <form method="post"> 
     <label>Name:</label><input type="text" name="name"></br> 

     <label>Date:</label><input type="text" name="date"></br> 


     <input type="button" value="Submit" onclick="window.location.href='phpfile.php?SubmitType=1';"> 
     <input type="button" value="Start Over" onclick="window.location.href='phpfile.php?SubmitType=2';"> 

     </br> 
    </form> 
</div> 

<?php 
if ($_GET['SubmitType'] == '1') { 



    $name = $_POST['name']; 
    $date = $_POST['date']; 

    echo "Name: $name</br></br>"; 
    echo "Date: $date</br>"; 

    $file_handle = fopen("file.csv", "r"); 


     while (!feof($file_handle)) { 

      $fields_of_text = fgetcsv($file_handle, 2024); 

      $f = $fields_of_text; 
      $format = "%s %s %s %s %s %s %s %s %s %s %s"; 
      echo "<br>" . sprintf($format, $f[0], $f[1], $f[2], $f[3], $f[4], $f[5], $f[6], $f[7], $f[8], $f[9], $f[10]); 

      echo "<br>"; 

      echo "<br>"; 
      echo "<br>"; 
     } 

     fclose($file_handle); 


    } 
    else { 
     header("Location: phpfile.php"); 
     exit(); 
    } 
?> 
</div> 
</body> 
</html>