因此,我有一个名为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);
}
?>
发布于 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'];?>">
https://stackoverflow.com/questions/51181719
复制相似问题