Youssef
Chevereto Member
1. Create a Database Table
Create a database with any name, but create a database table named comments with the following columns.
2. Connecting to Database & Selecting Database
3. Creating Comment HTML Form
4. Inserting Submitted Form Data into Database Table
5. Displaying Comments in Back-end
6. Edit & Update Comments
7. Comment Status Update
8. Deleting Comments
Create a database with any name, but create a database table named comments with the following columns.
- ID is integer type & autoincreement
- Name is varchar type, it is used to store name field from comment form.
- E-Mail is varchar type, it is used to store the email from comment form.
- Subject is varchar type, it is used to store the comment text from comment form.
- Submittime is datetime type, it is used to store the time of comment submission by setting default to current_timestamp.
- Status is also varchar, it is used to store the status of comment. That is comment is published or not.
SQL:
-- Table structure for table `comments`
--
CREATE TABLE `comments` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`subject` varchar(255) NOT NULL,
`submittime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2. Connecting to Database & Selecting Database
3. Creating Comment HTML Form
HTML:
-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
HTML:
<div class="panel panel-default">
<div class="panel-heading">Submit Your Comments</div>
<div class="panel-body">
<form method="post">
<div class="form-group">
<label for="exampleInputEmail1">Name</label>
<input type="text" name="name" class="form-control" id="exampleInputEmail1" placeholder="Name">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Subject</label>
<textarea name="subject" class="form-control" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
4. Inserting Submitted Form Data into Database Table
PHP:
require('connect.php');
PHP:
isset($_POST) & !empty($_POST)){
$name = mysqli_real_escape_string($connection, $_POST['name']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$subject = mysqli_real_escape_string($connection, $_POST['subject']);
$isql = "INSERT INTO comments (name, email, subject, status) VALUES ('$name', '$email', '$subject', 'draft')";
$ires = mysqli_query($connection, $isql) or die(mysqli_error($connection));
if($ires){
$smsg = "Your Comment Submitted Successfully";
}else{
$fmsg = "Failed to Submit Your Comment";
}
}
5. Displaying Comments in Back-end
HTML:
<div class="panel panel-default">
<div class="panel-heading">Comments</div>
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Comment</th>
<th>Time</th>
<th>Status</th>
<th>Operations</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Comment ID</th>
<td>Name</td>
<td>Comment</td>
<td>Comment Time</td>
<td>Comment Status</td>
<td><a href="#">Edit</a> <a href="#">App</a> <a href="#">Dis</a> <a href="#">Del</a></td>
</tr>
</tbody>
</table>
</div>
6. Edit & Update Comments
7. Comment Status Update
8. Deleting Comments
Last edited: