Welcome to part 4 of this 5 part tutorial. This section will handle the comment system that allows users to port what they think about the tutorial you have posted. Unlike the last 2 sections of this tutorial, this one will not need an add page in the admin panel because all the comment adding will be done from the tutorial page. This section will be useless until you have completed part 5, so don’t worry if things aren’t working just yet. Every page we create in this section will go into the admin folder.
So lets start with making comments.php and adding the following code to it.
$id = $_GET['id'];
$query = "SELECT * FROM comments WHERE id = '".mysql_real_escape_string($id)."' ORDER BY cid ASC";
$result = mysql_query($query) or die("Error in query: $query . " . mysql_error());
if(mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_object($result))
{
?>
<table width="100%" border="0">
<tr>
<td class="text"><h1><?php echo $row->cid; ?> – <?php echo $row->ip; ?>: <?php echo $row->name; ?>, <?php echo $row->email; ?> – <?php echo $row->date; ?></h1></td>
</tr>
<tr>
<td class="text"><?php echo $row->comment; ?></td>
</tr>
<tr>
<td class="text"><a href="edit_comment.php?id=<?php echo $row->cid; ?>">Edit</a> | <a href="delete_comment.php?id=<?php echo $row->cid; ?>" onclick="return confirm('Are you sure you want to delete this comment?')">Delete</a></td>
</tr>
</table>
<hr class="news">
<?php
}
}
else
{
?>
No comments!<hr>
<?php
}
mysql_close($connection);
?>
This page will simply display all the comments for a certain tutorial and provide links to manage them. It will use the ?id= in the URL to fetch the id of the tutorial and then grab any comments from that tutorial and display them.
Now, as I mentioned just before this tutorial section needs no add page, so we will jump straight to edit_comment.php. Add the following code to it.
if (!isset($_POST['submit']))
{
if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
{
die ('Missing record ID!');
}
$id = $_GET['id'];
$query = "SELECT * FROM comments WHERE cid = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_object($result);
$comment = stripslashes(strip_tags(htmlspecialchars($row->comment, ENT_QUOTES)));
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<h1>Edit comment #<?php echo $id; ?></h1>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<h2>Name</h2>
<input value="<?php echo stripslashes($row->name); ?>" name="name" type="text" size="50"><br>
<br>
<h2>Email</h2>
<input value="<?php echo stripslashes($row->email); ?>" name="email" type="text" size="50"><br>
<br>
<h2>Comment</h2>
<textarea name="comment" cols="50" rows="4"><?php echo $comment; ?></textarea>
<p>
<input name="submit" type="Submit" value="Submit">
<input type="reset">
</p>
</form>
<?php
}
else
{
echo 'Comment not found!';
}
}
else
{
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$query = "UPDATE comments SET name = '".$name."', email = '".$email."', comment = '".$comment."' WHERE cid = '".$id."'";
$result = mysql_query($query)or die(mysql_error());
echo 'Comment successfully edited. <a href="index.php">Go back to admin home page</a>';
}
mysql_close($connection);
?>
This works the same way as all the other edit forms, so I feel there is no need to explain it again.
Now screaming a lot to our already last document for this section, we have delete_comment.php. Add the following code to it.
if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
{
die('Missing record ID!');
}
$id = $_GET['id'];
$query = "DELETE FROM comments WHERE cid = '$id'";
$result = mysql_query($query)
or die ("Error in query : $query. " . mysql_error());
echo 'Comment successfully deleted';
mysql_close($connection);
?>
This is our simplest of all our delete pages. All this one does is deletes the comment you have selected. It knows what comment it is by fetching the id from ?id= in the URL.
Were done that section already. Short wasn’t it. Only one section left to go. Good news, the entire admin panel is complete! It will not all be working at the moment, but all the files are there and ready to work when you have completed the next section. There are links below to the next section of previous sections if you wish to look back on something.
« Previous [1] [2] [3] [4] [5] Next » | Download ZIP
Fantastic, nice gb design. What CMS do you use ?
Fantastic, nice gb style of site. What CMS do you use ?
Wow, beautiful gb style of site. What CMS do you use ?
Прикольный сайт, жду вас у меня
http://surveys.do.am/
drugs affect circulatory system
fixtinhot lasix medication No prescription. lasix price Lasix is a brand name that markets for the chemical furesomide, which is used for the treatments of heart failure and edema in human beings. http://www.foxspizzalasvegas.com/ – furosemide online No prescription.
[...] « Previous [1] [2] [3] [4] [5] | Download ZIP More… Join our RSS feed Digg Del.icio.us Reddit Furl addthis_pub = 'designkai'; addthis_logo_background = 'EFEFFF'; addthis_logo_color = '666699'; addthis_brand = 'Designkai.com'; addthis_options = 'favorites, digg, delicious, google, myspace, facebook, reddit, newsvine, live, more'; 4 Replies… scott [...]
[...] Previous [1] [2] [3] [4] [5] Next » | Download ZIP More… Join our RSS feed Digg Del.icio.us Reddit Furl [...]
RSS feed for comments on this post. TrackBack URL