首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >php sql将ID和文本导入到testarea,然后在对文本进行更改后发布这两个值

php sql将ID和文本导入到testarea,然后在对文本进行更改后发布这两个值
EN

Stack Overflow用户
提问于 2018-07-05 07:24:51
回答 1查看 17关注 0票数 0

因此,我有一个名为Names.html.php的文件,它可以很容易地显示我的sql表中的数据。它有一个编辑和删除按钮。编辑按钮允许用户编辑表的“备注”列中的文本,该列是长文本值(但确实以文本开头)。

编辑按钮将所选记录的ID发送到EditNote.php,然后使用databasefunctions.php中的函数打开该记录,并使用EditNote.html.php显示该记录。

当我更改“文本区域”框中的文本并单击“保存”时,不会出现错误,但表中的文本没有更新,这就是我的问题。我知道ID值是正确传递的,但我想知道是否存在Textarea发布不刷新的问题?或者有两个来自同一个表单的post值导致了一些问题?无论哪种方式,我都不确定如何解决这两个问题,因此如果能得到一些帮助,我们将不胜感激:)

Names.html.php

<blockquote>
  <p>

  <?=htmlspecialchars($Names['Name'], ENT_QUOTES, 'UTF-8')?>
  <?=htmlspecialchars($Names['Notes'], ENT_QUOTES, 'UTF-8')?>
  <?=htmlspecialchars($Names['Punch_IN_Time'], ENT_QUOTES, 'UTF-8')?>
  <?=htmlspecialchars($Names['Status'], ENT_QUOTES, 'UTF-8')?>

  <a href="EditNote.php?idss=<?=$Names['Punch_ID']?>">Edit</a>

  <form action="DeleteEntry.php" method = "post">
    <input type="hidden" name="ids" value="<?=$Names['Punch_ID']?>">
    <input type="submit" value="Delete">
  </form>
  </p>
</blockquote>
<?php endforeach; ?>

EditNote.php

<?php
include '_DIR_' . '/../../Include/DatabaseConnection.php';
include '_DIR_' . '/../../Include/DatabaseFunctions.php';

try {
  if (isset($_POST['NotePage'])) {
    $note = (string)$_POST['NotePage'];
    $IDs = (int)$_POST['Pid'];

    UpdateNotes($pdo, $IDs, $note);

  header('location: Punchinoutlist.php');
  }else{
    $Note = getPunchLine($pdo, $_GET['idss']);

    $title = 'Edit Note';

    ob_start();

    include '_DIR_' . '/../../Templates/EditNote.html.php';

    $output = ob_get_clean();
  }
} catch (PDOException $e) {
  $title = 'An error has occurred';

  $output = 'Database error: ' . $e->getMessage() . ' in ' .$e->getFile() . ':' . $e->getLine();
}

include '_DIR_' . '/../../Templates/Layout.html.php';

 ?>

EditNote.html.php

<form action="" method="post">
  <input type="hidden" name"Pid" value="<?=$Note['Punch_ID'];?>">
  <label for = "NotePage">Type your new note here:
  </label>
  <textarea id = "NotePage" name="NotePage"
    rows="3" cols ="40"><?=$Note['Notes']?>
  </textarea>
  <input type="submit" value="Save">
</form>

DatabaseFunctions.php

// Main query function that all fucntions refer //

function query($pdo, $sql, $parameters = []){
  $query = $pdo->prepare($sql);
  $query->execute($parameters);
  return $query;
 }

//update function for updating the note column of a certain record in the punch_in_out table //

function UpdateNotes($pdo, $id, $Notes){
  $parameters = [':Notes' => $Notes, ':id' => $id];

  $query = 'UPDATE `punch_in_out` SET `Notes` = :Notes WHERE `Punch_ID` = :id';

  query($pdo, $query, $parameters);
}
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-05 07:31:27

看起来你在POST文本更新时没有得到你的ID,因为你的超文本标记语言中的name后面缺少了一个=

// you have
 <input type="hidden" name"Pid" value="<?=$Note['Punch_ID'];?>">

// you should have
 <input type="hidden" name="Pid" value="<?=$Note['Punch_ID'];?>">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51181719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档