doumi1912 2013-11-09 15:24
浏览 418

在HTML页面的TextArea中输入的文本未保存在文本文件中。

I am trying to save the data entered in HTML form in a text file. I am using a php script to do this. When I click on submit button, it does not save the data in text file. Can someone tell me what is going wrong here.

Below is the code snippet -

HTML Form -

<form id="post" name="post" method="post" action="input.php">
    Name: <input type="text" name="name"><br>
    Text: <textarea rows="50" cols="85" name="blogentry"></textarea>
    <input class="button" type="submit" value="Submit">
</form>

PHP - (input.php)

<html>
   <head></head>
   <body>
   <?php 

   // variables from the form
   $name = $_POST['name'];
   $blogentry = $_POST['blogentry'];

    // creating or opening the file in append mode
    $dataFile = "data.txt";
    $fh = fopen($dataFile, 'a');

    // writing to the file
    fwrite($fh, "Name - " . " " . $name . " " . "
");
    fwrite($fh, "Blog - " . " " . $blogentry . " " . "

");

    fclose($fh);
    ?>
   </body>
</html>
  • 写回答

4条回答 默认 最新

  • donglian8407 2013-11-09 15:30
    关注

    In cases like this it's useful to pinpoint the problem. Maybe the form isn't submitting your textarea, or maybe your PHP isn't receiving it, or maybe it's some problem with what you're doing with the value.

    If you view your form submission in an inspector like Firebug, do you see the contents of your textarea being submitted in the request?

    If you do a var_dump($_POST) in your code, do you see all the values being submitted from the form?

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题