【问题标题】:Taking notes with filename input not working html?用文件名输入做笔记不起作用html?
【发布时间】:2020-02-17 11:56:47
【问题描述】:

我在我的网站上添加了一个简单的不接受页面,它接受用户输入的文件名和注释数据。

但是,每当我运行代码时,我都会收到一堆错误和一些不工作的代码:

HTML 表单:

<form method="post">
    <div style="margin-right:">
      <input type="text" class="fileName" name="fileName" id="fileName" size="35"><br>
      <textarea type="text" name="notes" id="notes"></textarea><br>
      <input type="Submit" name="Submit" value="Save">
    </div>
</form>

PHP 形式:

$noteName = $_POST['fileName'];
(line 51:)$noteData = $_POST['notes'];

(line 53:)$notes = fopen('' + $noteName,"wb");
fwrite($notes,$noteData);
fclose($notes);

错误列表:

注意:未定义索引:C:\xampp\htdocs\NNDbase.php 第 51 行中的注释

警告:C:\xampp\htdocs\NNDbase.php 第 53 行中遇到的非数字值

警告:C:\xampp\htdocs\NNDbase.php 第 53 行中遇到的非数字值

【问题讨论】:

  • 你对POST-ing 这些行有什么检查吗,比如if(!empty($_POST['filename']))
  • 如果你在同一个文件中有这两个代码sn-ps,那么你需要首先检查是否真的有任何POST数据。因为最初显示表单的第一个请求将是 GET 请求,所以当然没有 POST 数据。

标签: php forms


【解决方案1】:

试试这个

 if($_POST){
    $noteName = $_POST['fileName'];
    $noteData = $_POST['notes'];
    $notes = fopen('' + $noteName,"wb");
    fwrite($notes,$noteData);
    fclose($notes);
}

【讨论】:

    猜你喜欢
    • 2016-11-27
    • 2017-04-18
    • 2014-03-19
    • 2018-01-11
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    相关资源
    最近更新 更多