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

php sql importing ID and Text to testarea then posting both values after changes were made to the Text

所以我有一个名为 Names.html.php 的文件,它可以轻松地在我的 sql table 中显示来自 table 的数据。它有一个编辑和删除按钮。编辑按钮允许用户编辑 table 的 "notes" 列中的文本,这是长文本值(但确实以文本开始)。

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

当我更改 Textarea 框中的文本并单击“保存”时,我的问题出现了,没有出现错误,但 table 中的文本没有更新。我知道 ID 值被正确传递,但我想知道 Textarea posting 不刷新是否有问题?或者有 2 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);
}
?>

当您 POST 文本更新时,您似乎没有获得您的 ID,因为您在 HTML 中的 name 之后缺少一个 = =].

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

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