我目前正在尝试将其保存在文件中。但它不会工作。
有谁知道我做错了什么?当我按下verturen
按钮时我的目标是保存值,
r
或o
在g
文本文件中,然后将其保存在$s1array
. 之后,如果我按下载,他会将其加载$s1array
到文本文件中。我想$s1array
在剩下的时间里保持新的价值。
(这是我的代码)
<form method="post">
<input type="submit" name="submit1" value="Versturen">
<select name="state1sl1">
<option name="groen" value="g">groen</option>}
<option name="oranje" value="o">oranje</option>
<option name="rood" value="r">rood</option>}
</select>
<select name="state1sl2">
<option name="groen" value="g">groen</option>}
<option name="oranje" value="o">oranje</option>
<option name="rood" value="r">rood</option>}
</select>
<select name="state1sl3">
<option name="groen" value="g">groen</option>}
<option name="oranje" value="o">oranje</option>
<option name="rood" value="r">rood</option>}
</select>
</form>
<form method="post">
<input type="submit" name="download" value="download">
</form>
<?php
if(isset($_POST['submit1'])){
$_name1 = $_POST['state1sl1'];
$_name2 = $_POST['state1sl2'];
$_name3 = $_POST['state1sl3'];
$my_File = 'T-Splitsing.txt';
$fh = fopen($my_File, 'w') or die("can't open file");
fwrite($fh, $_name1);
fwrite($fh, $_name2);
fwrite($fh, $_name3);
fclose($fh);
$s1array = file_get_contents("T-Splitsing.txt");
}
if(isset($_POST['download'])){
$file = 'T-Splitsing.txt';
if (file_exists($file)) {
$my_File = 'T-Splitsing.txt';
$fh = fopen($my_File, 'w') or die("can't open file");
fwrite($fh, $s1array);
fclose($fh);
?>