如何创建从txt文件反馈数据的textarea

时间:2015-02-12 18:37:27

标签: php html html5

晚上好。 首先对网络开发领域的新手表示歉意。我正在尝试创建一个可以输入文本的文本区域,刷新页面后会在文本区域上方显示该文本,以便我可以引用它。

我正在分阶段工作,到目前为止,我真的很难将用户输入从html转换为php,然后将其重新插入该页面。 有人可以解释一下如何做到这一点吗?

我的代码包含在

下面
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>HTML php</title>
<link href="" rel="stylesheet" type="text/css" media="screen"> <!-- link to      CSS sheet -->
</head>
<body>
<h1>HTML php</h1>

<?php
//***************************************
// Gather Data from Form
//***************************************


 $HTMLNotes = $_POST['HTML_notes'];

 $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];

 $filename = $DOCUMENT_ROOT.'First Website/HTML/Html_Notes.txt';




 //***************************************
 //Add Name Information to File
 //***************************************

 $fp = fopen($filename, 'a');   //opens the file for appending

 $output_line = $HTMLNotes.'|'."\n";

 fwrite($fp, $output_line);

 fclose($fp);

 print "<h3>$HTMLNotes Added to File</h3>";

 ?>

<div class="container clearfix">

<?php

//--------------------------------------
//Reading info from file
//--------------------------------------

//Table of names --------------------------



    $display = "";
    $line_ctr = 0; //line counter

    $fp = fopen($filename, 'r'); //opens the file for reading

    while(true)
    {
        $line = fgets($fp); //gets one line at a time

        if (feof($fp)) //eof = end of file
        {
            break;
        }

        $line_ctr++;

        $line_ctr_remainder = $line_ctr % 2; //modulus of 2 and returns the   remainder so even will always return 0

        list($HTMLNotes) = explode('|', $line);

            print "<p>".$HTMLNotes."</p>";
            print "</tr>\n";  //added newline
               //added newline


    }

    fclose ($fp );

    print $display; //this prints the table rows





?>


 </div>
 </body>
 </html>

这是PhP,HTML在下面。对不起它一团糟

 <!DOCTYPE HTML>

<html>

<head>
    <meta charset="UTF-8">
    <title>HTML</title>
    <link href="../CSS/Style.css" rel="stylesheet" type="text/css" media="screen"> <!-- link to CSS sheet -->
    <link href="../CSS/normalise.css" rel="stylesheet" type="text/css" media="screen"> <!-- link to normalised CSS form, this keeps standard normal elements for browsers. -->
</head>
<body>

<header>

        <div class="container clearfix">
            <a href="../index.html" title="Return to home" id="Logo">
                <img src="../IMAGES/Logo.gif" alt="Logo">

            </a>

            <nav>
                <ul>
                    <li><a href="../index.html">HOME</a></li>
                    <li><a href="HTML.html">HTML</a></li> 
                    <li><a href="CSS.html">CSS</a></li>
                    <li><a href="LINKS.html">LINKS</a></li>
                </ul>
            </nav>
        </div> <!-- end div container -->   

</header>

    <div id="mainheader"> <!--hero -->
            <div class="container clearfix">
                <div id="Title">

                    <h1>HTML Resources and References</h1>

                </div> <!--end of title -->

                    <img src="../IMAGES/BigHTML.png" alt="Large HTML Logo" id="HTML-image">
            </div> <!-- end of container -->
    </div> <!--end of mainheader -->

</header> <!--end of header -->


<div id="content" class="container clearfix">

<form method="post" action="HTML.php">

    <p>
    HTML notes:<br />
    <textarea name="HTML_notes" rows="7" cols="130">
    </textarea>
    </p>

    <p>
        <input type="submit" class="Btn Btn-small" value="Submit Information">
    </p>

</form>


</div> <!-- end of content -->


<div id="LowerSection">
        <div class="container clearfix">
            <h4>Sign up on the website to find out more information</h4>
            <form>
                <input type="email" placeholder="Enter your email here">
                <input type="submit" class="Btn Btn-small" value="Sign up">
            </form> 
        </div> <!-- end of container-->

    </div> <!-- end of LowerSection -->



    <footer>
        <div class="container clearfix">
            <p id="copyright">Copyright &copy; 2015 AaronMurphy</p> <!--   using the & with a word reduces errors and creates symbols -->

            <nav>
                <ul>
                    <li><a href="../index.html">HOME</a></li>
                    <li><a href="HTML.html">HTML</a></li> 
                    <li><a href="CSS.html">CSS</a></li>
                    <li><a href="LINKS.html">LINKS</a></li>
                </ul>
            </nav>
        </div> <!-- end of conatiner -->


    </footer>
 </body>
 </html>

0 个答案:

没有答案