我需要在我的数据库中创建一个记录,当用户编辑描述字段时,它会将其保存到数据库中(目前可以这样做)。但是当用户想要在先前添加的同一个便笺中添加另一个便笺时,它只会保存旧便笺(我正在使用更新)。
所以我想知道如何做到这一点?在下面的代码中,您将看到我有两个文本区域,一个用于显示数据库中的记录,另一个用于向数据库添加新注解。理想情况下,我希望在一个新的未编辑的文本区域中显示每个新注解(有点像显示添加到原始注解的所有注解的历史记录)。
<?php
require_once '../config.php';
$description_err = "";
if(isset($_POST["id"]) && !empty($_POST["id"])){
$id = $_POST["id"];
$input_description = trim($_POST["descriptionfield"]);
if(empty($input_description)){
$description_err = "Please enter a description.";
} else{
$description= $input_description;
}
if(empty($description_err)){
$sql = "UPDATE newtask SET new_description=? WHERE id=?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "si", $param_description, $param_id);
$param_description = $description;
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
header("location: user-dashboard.php");
exit();
} else{
echo "Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($link);
} else{
if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){
$id = trim($_GET["id"]);
$sql = "SELECT * FROM newtask WHERE id = ?";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "i", $param_id);
$param_id = $id;
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1){
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$description = $row["new_description"];
} else{
header("location: ../error.php");
exit();
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
mysqli_stmt_close($stmt);
mysqli_close($link);
} else{
header("location: ../error.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-
scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Support Admin</title>
<link href="../assets/css/bootstrap.css" rel="stylesheet" />
<link href="../assets/css/font-awesome.min.css" rel="stylesheet" />
<link href="../assets/css/style.css" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Nova+Flat"
rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,700,300"
rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="head">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<a href="../index.php">
<img src="../assets/img/logo1.png" />
</a>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text-center" >
<img src="../assets/img/top-mouse.png " class="header-mid"
/>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h4><span>Call:</span> 082 </h4>
<h4><span>E-mail:</span> sales</h4>
</div>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row noti-div">
<div class="col-lg-3 col-md-3 col-sm-3 text-center">
</div>
</div>
</div>
</section>
<section id="main">
<div class="container">
<div class="row">
<div class="col-lg-9 col-md-9 col-sm-9 alert alert-info">
<h3 class=" text-center">Update Task</h3>
<div class="hr-div"> <hr />
</div>
<form action="<?php echo
htmlspecialchars(basename($_SERVER['REQUEST_URI']));
?>" method="post">
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?
php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>New Note<textarea name="descriptionfield"
class="formcontrol</textarea>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<label>Note Added By </label>
<textarea class="form-control"><?php echo $description; ?></textarea>
</div>
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<a href="index.php" class=" label label-danger">
<strong>LOGOUT</strong> </a>
<div class="list-group">
<a href="#" class="list-group-item active">Quick Links
</a>
<a href="user-dashboard.php" class="list-group-item">My Dashboard</a>
<a href="open-tickets.php" class="list-group-item">Open Tasks</a>
<a href="notifications.php" class="list-group-item">Pending Tasks</a>
<a href="ticket-history.php" class="list-group-item">Completed Tasks</a>
<a href="change-password.html" class="list-group-item">Change Password</a>
</div>
<div class="alert alert-success text-center">
<h3>The Notice Board</h3>
No Notice Found !
</div>
<div class="list-group">
<a href="#" class="list-group-item active">Support Categories</a>
<a href="#" class="list-group-item">Notes</a>
<a href="#" class="list-group-item">Manuals</a>
<a href="#" class="list-group-item">General Information</a>
</div>
</div>
</div>
</div>
</section>
<div id="footer">
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>This</h3>
</div>
<div class="col-lg-4 col-md-4 col-sm-4">
<h3>Contact Details</h3>
</div>
</div>
</div>
</div>
<script src="assets/js/jquery-1.10.2.js"></script>
<script src="assets/js/bootstrap.js"></script>
</body>
</html>
因此,正如您在上面的代码中看到的,它正在更新我的“newtask”表,我假设它需要更新名为“updatedata”的新表(这不在上面的代码中,因为我不确定如何添加它以及两个表的id)
然后显示“newtask”表(原始表)中的数据。
根据我上面的问题,我将如何实现这一目标?
谢谢你们
编辑
因此,从下面的图像中,我希望有“updatedata”表中的文本链接到“newtask”表中的id 1。然后在我的页面的不同div中显示该文本。
我想链接从更新数据到newtask的所有新文本,而不必过度写入newtask中已有的数据。
所以我想显示如下
暂无答案!
目前还没有任何答案,快来回答吧!