0

我目前正在使用 php 写入文本文件。有两件事做得不好。第一个是,我不能跳新线,尝试了很多方法。第二件事是我无法从选定的选项中读取值。有什么解决办法吗?

php 与 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);

?>
4

1 回答 1

1

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

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

于 2013-03-08T20:00:02.443 回答