换行并从php文件的选项中读取

时间:2013-03-08 19:55:36

标签: php html newline option fwrite

我目前正致力于使用php编写文本文件。有两件事情做得不好。首先,我不能跳过一条新线,尝试了很多方法。第二件事是我无法从选定的选项中读取值。任何解决方案?

php with html

<!DOCTYPE html>

<html>

<head>
<title>Inlämning3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jQuery.js" >
</script>
<script type="text/javascript" src="valideraFilmer.js" >
</script>

</head>

<body>
<div id="page">
    <?php
        include("header.php");
    ?>
    <div id="leftbar">
        <form id="form" method="POST" action="hanteraFilmer.php">
            <fieldset>
                <legend>Lägg till en film:</legend>
                Titel:
                <br><input type="text" name="name" id="name"><br>
                Betyg:
                <br><select id="options">
                    <option value="0">Välj betyg här...  </option>
                    <option value="*"> *</option>
                    <option value="**"> **</option>
                    <option value="***"> ***</option>
                    <option value="****"> ****</option>
                    <option value="*****"> *****</option>                       
                </select>
                <br>
                Länk till imdb:
                <br><input type="text" name="link" id="link"><br>
                Länk till bild:
                <br><input type="text" name="pic" id="pic"><br>
                Filmens handling:
                <br><textArea cols="20" rows="3" name="story" id="story"></textarea><br>
                <br><input type="submit" name="button" value="Spara film" id="button">
            </fieldset>
        </form>
    </div>
    <div id="rightbar">
        <h2>Filmer</h2>
    </div>
    <?php
        include("footer.php");
    ?>
</div>
</body>

</html>

php

<?php

$name = $_POST['name'];
$grade = $_POST['options'];
$link = $_POST['link'];
$pic = $_POST['pic'];
$story = $_POST['story'];

$myFile = "filmer.txt";
$handle = fopen($myFile, 'a');

fwrite($handle, $name. ";");
fwrite($handle, $grade. ";");
fwrite($handle, $link. ";");
fwrite($handle, $pic. ";");
fwrite($handle, $story. "/n");
fclose($handle);

?>

1 个答案:

答案 0 :(得分:1)

您可以在name中添加属性<select id="options">,例如<select id="options" name="options'>

它应该是"\n",而不是"/n"