每次在php中执行代码时,如何创建新的测验表单?

时间:2019-06-19 04:21:25

标签: php

我需要创建一个测验,但是我不能使用MySql数据库,所以我在该项目中只能使用纯文本文件和纯php。因此,到目前为止,我已经创建了该程序,它有6个问题:4用于texboxes 2,用于单选按钮。 执行代码时,它会创建一个新的唯一顺序文本文件[0] .txt,file [1] .txt,file [2] .txt ...,并且每次执行该代码时都会创建一个新的文本文件。现在将问题和答案作为变量存储在文本文件中。现在我的想法是循环表单,但我不知道如何循环表单,以便每次执行代码时都会创建一个新表单。存储在新表格中,就像file [0],txt,file [1],txt.file [2] .txt ...一样。然后每次执行代码时,都会创建一个新的超链接,用户可以在其中回答问题我的变量是从文本框中发布的。谢谢。

<?php
if(isset($_POST['submit'])) {
    $k = 0;
    while ( ! $result ) {
        if ( !file_exists( "file[$k].txt" ) ) {
            $result = "file[$k].txt";
        }
        $k++;
    }
$file = fopen( $result, "w" );
    $question1 = $_POST['name'];
     $question2 = $_POST['name1'];
      $question3 = $_POST['name2'];
       $question4 = $_POST['name3'];
        $question5 = $_POST['name4'];
          $question6 = $_POST['name5'];
            $answer1 = $_POST['age'];
              $answer2 = $_POST['age1'];
               $answer3 = $_POST['age2'];
                $answer4 = $_POST['age3'];
                  $answer5 = $_POST['age4'];
                     $answer6 = $_POST['age5'];
                        $answer7 = $_POST['age6'];
                           $answer8 = $_POST['age7'];
                              $answer9 = $_POST['age8'];
                                  $answer10 = $_POST['age9'];
    $s = $question1 . "," . $answer1 . "," .$question2 . "," . $answer2 . "," .$question3 . "," . $answer3 .",". $answer5."," .$answer4.",".$answer6.",". $question4 .",". $answer7."," .$answer8.",". $answer9 .",". $question5."," .$answer9.",".$question6. "\n";
    fputs( $file, $s ) ;
}


else{
    echo
    "<center>
 <form action = 'wqd.php'  method = 'post'>
  <br><b>Question you want ask the person 1<b><br><input  type  = 'text' name='name'> <br>
   <br><b>Answer 1<b><input type = 'text' name = 'age'><br>
   <br><b>Question you want ask the person 2<b><br><input  type  = 'text' name='name1'> <br>
   <br><b>Answer 2<b><input type = 'text' name = 'age1'><br>
    <br><b>Question you want ask the person 3<b><br><input  type  = 'text' name='name2'> <br>
   <br><b>Answer 3<b><input type = 'text' name = 'age2'><br> 
      <br><b>Question you want ask the person 4<b><br><input  type  = 'text' name='name3'> <br>
   <br><b>Answer 4<b><input type = 'text' name = 'age3'><br>  
    <br><b>Answer 4<b><input type = 'text' name = 'age4'><br> 
     <br><b>Answer 4<b><input type = 'text' name = 'age5'><br> 
          <br><b>Question you want ask the person 5<b><br><input  type  = 'text' name='name4'> <br>
   <br><b>Answer 5<b><input type = 'text' name = 'age6'><br>  
    <br><b>Answer 5<b><input type = 'text' name = 'age7'><br> 
     <br><b>Answer 5<b><input type = 'text' name = 'age8'><br> 
          <br><b>Question you want ask the person 6<b><br><input  type  = 'text' name='name5'> <br>
   <br><b>Answer 6<b><input type = 'text' name = 'age9'><br>  
     <input type = 'submit' name = 'submit' value = 'Make  Questions'>         
    </center>";}


?>

输出:新形式:question1回答1;

0 个答案:

没有答案