如何将选定的选项保存到php中的txt文件中?

时间:2019-06-02 11:01:52

标签: php

我想将选定的选项(颜色和喜欢的歌曲)保存到result.txt文件中。它已经保存了,但是保存了空值。有人可以解释为什么保存空值吗?它说未定义索引:颜色输入...,未定义索引:歌曲输入...这是我的代码

<?php
   echo "<meta charset='utf-8'>";

   echo "<form method='get' action='ques.php'>
what color do you like? <br>";   
$co = file('color.txt');
$col = ' ';
$col.="<option>choose</option>";
foreach ($co as $color) { 
    $choose = explode('-',$color);
    $col .= '<option value="'.$choose[0].'">'.$choose[0].'</option>';
}
$select = '<select name="color">'.$col.'</select>';
echo $select;


  echo "<br><br>What is yor favourite song? <br>";            
$song = file('song.txt');
$sing = '-';
$sing.="<option>choose</option>";
foreach ($song as $son) {
    $choosen = explode('-',$son);
    $sing .= '<option value="'.$choosen[0].'">'.$choosen[0].'</option>';
}
$select = '<select name="song">'.$sing.'</select></form>';
echo $select; 


  echo "<form method='get' action='ques.php'>
<br><input type='submit' name='save' value='Save it'>
 </form>";      



   if (!empty($_GET['save'])){

      $fl="result.txt";
      $flo=fopen($fl,"a");
      $content=$_GET["color"]."*".$_GET["song"]."*=\r\n";
      fputs($flo,$content);
      fclose($flo);   
}
?>

0 个答案:

没有答案