我在将新发布的数据附加到现有数据时遇到问题。
现在,当单击submit按钮时,它将仅用$header和新的$u post[“notes”]值覆盖“notes”的现有值。
我希望它做的是:$header+$\u post[“notes”]+$notes(现有数据)
这是我目前的代码:
<?php
// Database connection file
include_once("../config.php");
// Get id from url
$id = $_GET['id'];
// Selecting data associated with this id
$sql = "SELECT * FROM testtable WHERE id=:id";
$query = $dbConn->prepare($sql);
$query->execute(array(':id' => $id));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$notes = $row['notes'];
}
?>
<?php
// Create Header
$header = "----- Updated on " . date("Y-m-d") . " at " . date("h:i:sa") . " ----- <br>";
// Current note data
$currentnotes = $notes;
// Append Header + Post + Current Data
$appendednotes = $header;
$appendednotes .= $_POST["notes"];
$appendednotes .= "<br>";
$appendednotes .= $currentnotes;
if(isset($_POST['update'])){
$id = $_POST['id'];
$notes=$appendednotes;
// Update the table
$sql = "UPDATE testtable SET
notes=:notes
WHERE id=:id";
$query = $dbConn->prepare($sql);
$query->bindparam(':id', $id);
$query->bindparam(':notes', $notes);
$query->execute();
// Redirect to the display page
header("Location: index.php");
}
?>
这是找到我想要做的事情的最接近的例子,但是我不确定如何调整它:php post to variable,然后append to txt
1条答案
按热度按时间6uxekuva1#
多亏了paul,我把代码更新到了这个版本,而且还可以用!