<html xmlns="http//www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type"
content="text/html; charset=
iso-8859-1" />
<title>View my blog</title>
<?php // view_blog.php This script connects to the MySQL server.
//This script retrieves blog entries from the database
// Address Error Handling
ini_set ('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);
// Connect and select
include('dbc_sql_db_inc.php');
// Define the query
$query = ' SELECT * FROM blog_entries ORDER BY date_entered DESC';
if ($r =mysql_query ($query)) { // Run the query
// Retrieve and print every record
while ($row = mysql_fetch_array ($r)) {
print "<p><h3>{$row['title']}</h3>
{$row['entry']}<br />
<a href=\"edit_entry.php?id=
{$row['blog_id']}\">Edit</a>
<a href=\"delete_entry.php?id=
{$row['blog_id']}\">Delete</a>
</p><hr />\n";
}
} else { // Query did not run
die(’
Could not retrieve the data
because: ’ . msql_error() . “.
The query was $query,
”);
} // End of query IF
mysql_close();
?>
<html xmlns="http//www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type"
content"text/html; charset=
iso-8859-1" />
<title>Edit a blog entry</title>
<?php // edit_entry.php
//This script edits a blog entry using UPDATE
// Address Error Handling
ini_set ('display_errors',1);
error_reporting (E_ALL & ~E_NOTICE);
include('dbc_sql_inc.php');
if (isset ($_POST[‘submit’]))
{ // Handle the form
// Define the query
$query = “UPDATE blog_entries SET title=’{$_POST[‘title’]}’, entry=’{$_POST[‘entry’]}’ WHERE
blog_id={$_POST[‘id’]}”;
$r = mysql_query ($query); // Execute the query
//REPORT ON THE RESULT
if (mysql_affected_rows() == 1) {
print ’
The blog entry has been updated.
’;
} else
{print "
Could not update the entry because: " . mysql_error(). “. The query was $query.
”;
}
} else { // Display the entry in a form
// Check for a valid entry ID in the URL
if(is_numeric ($_GET[‘id’])) {
//Define the query
$query = “SELECT * FROM blog_entries WHERE blog_id={$_GET[‘id’]}”;
if ($r = mysql_query ($query)) {// Run the query.
$row = mysql_fetch_array($r);// Retrieve the infORMATION
//Make the form
print ’
Entry Title:
Entry Text: ' . $row['entry'] .
'
';
} else { // Could not get the information.
print "
Could not retrieve the entry because: " . mysql_error() . ". The
query was $query.
";
}
} else { // No ID set
print '
You must have made a
mistake inusing this page.
';
}
} // End of main IF
mysql_close(); // Close the database connection.
?>