如何让程序读取question.php上生成的时间文本文件?
该文件有一个2 texbox提交按钮,当点击该按钮时,数据被放入新创建的文件中。每个新创建的文件 我有一个文件j.php,它创建了一个texfile问题。$myDate.txt创建了一个具有唯一名称的新txt文件,$question1表示问题,它作为符号“,”拆分$question1和$question2的第一个元素放在文本文件数据中。变量$question2表示答案。并将第二个元素放入文本文件中。 第二个文件questions.php在按钮提交后立即打开。由于文本文件包含两个元素,因此文件被假定为读取并拆分文本文件的数据,并在文本文件拆分为两个元素后读取并显示。第一个问题显示为一个问题,texbox中应该写一个答案,然后提交表格。 但是文件2上的问题是它没有读取文本文件数据。当文本框弹出时如何让程序读取question.php上生成的时间文本文件?,php,Php,该文件有一个2 texbox提交按钮,当点击该按钮时,数据被放入新创建的文件中。每个新创建的文件 我有一个文件j.php,它创建了一个texfile问题。$myDate.txt创建了一个具有唯一名称的新txt文件,$question1表示问题,它作为符号“,”拆分$question1和$question2的第一个元素放在文本文件数据中。变量$question2表示答案。并将第二个元素放入文本文件中。 第二个文件questions.php在按钮提交后立即打开。由于文本文件包含两个元素,因此文件被假
<?php
if(isset($_POST['submit'])) {
$number =$number +1;
$myDate = round(10*microtime(TRUE));
$result ="question".$myDate.".txt";
$question1 = $_POST['name'];
$question2 = $_POST['age'];
$file = fopen( $result, "w+" ) or die( "file not open" );
$s = $question1 . "," . $question2 . "\n";
fputs($file, $s)or die("Data not written");
// Here - redirect to questions.php to display the contents.
header('Location: questions.php');
die;
}
else{
echo
'<center>
<form action = "j.php" method = "post">
<br>Question you want ask the person <input type = "text" name="name"> <br>
<br>Answer<input type = "text" name = "age"><br>
<input type = "submit" name = "submit" value = "Make Question">
</form>
</center>';}
?>
<?php
$myDate = glob("*.txt");
$myFile = "question".$myDate."txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$arr =explode(",",$theData);
$x=$arr[0];
$y = $arr[1];
$text = $_POST["name"];
$text = true;
if($_POST['submit']) {
$text = $_POST["name"];
if ( $text ==$y) {
echo "<font color = 'red'>Your answer is incorrect</font>";
} else {
echo "answer not correct";
}
}
?>
<center>
<form method = "post">
<?php echo $x ?> <input type = "text" name="name"> <br>
<input type = "submit" name = "submit" value = "Submit answer">
</form>
</center>
\\expected output the texfile being read and next to the text box the question popped upp\\