I need to create a record in my database that when a user edits the description field it would save it to the database (this currently works). But when the user wants to add another note to the same note added earlier it just saves over the old note. (am using UPDATE for that).
So I would like to know how to achieve this? In my code below you will see that I have two text areas, 1 to display the record from the database and the other to add a new note to the database. Ideally I would to like to display each new note in a new unedited-able text area (sort of like displaying the history of all notes added to the original note.
<?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>
So as you can see in the above code its updating my "newtask" table which I would assume that it needs to update the new table called "updatedata" (this is not in the code above as I am not sure how to add it as well as the id of the two tables)
It then displays the data from the "newtask" table (Original table).
How would I go about to achieve this as per my question above?
Thanks guys
EDIT
So as from the below image I want to have the text from "updatedata" table to link to id 1 from "newtask" table. And then display that text in different div in my page.
I would like to link all the new texts from update data to newtask without over writing the data already in newtask.
So I would to display like the below