Cleaned up ugly HTML and renamed index.php to simplog.php

This commit is contained in:
Jack-Benny Persson 2013-07-27 23:38:17 +02:00
parent 40de6d2290
commit e886d4f461
10 changed files with 82 additions and 37 deletions

8
includes/dbclose.php Normal file
View File

@ -0,0 +1,8 @@
<?php
// Close MySQL link
mysql_free_result($result);
mysql_close($link);
?>

18
includes/htmlcode.php Normal file
View File

@ -0,0 +1,18 @@
<?php
function start_html($title)
{
print "
<html>
<head>
<title>$title</title>
</head>
<body>\n";
}
function end_html()
{
print "\n\n</body>\n</html>\n";
}
?>

View File

@ -4,11 +4,10 @@
require "includes/config.php"; require "includes/config.php";
require "includes/dbconnect.php"; require "includes/dbconnect.php";
// Divide the posts into pages, N number of posts on every page // Divide the posts into pages, N number of posts on every page
if (isset($_GET["page"])) if (isset($_GET['page']))
{ {
$page = $_GET["page"]; $page = $_GET['page'];
} }
else else
{ {
@ -24,11 +23,10 @@ $result = mysql_query($query)
// Printing posts in HTML // Printing posts in HTML
while ($line = mysql_fetch_array($result)) while ($line = mysql_fetch_array($result))
{ {
print "<h2>" . $line['title'] . "</h2>"; print "<h2>$line[title]</h2>\n<p>";
print "\n<p>"; print "$line[posttext]\n<br />";
print $line['posttext']; print "Posted on: $line[date]";
print "\n<br/>" . $line['date']; print "</p>\n\n";
print "</p>";
} }
// Printing page links // Printing page links
@ -43,10 +41,8 @@ for ($i=1; $i<=$total_posts; $i++)
print "<a href='index.php?page=".$i."'>".$i."</a> "; print "<a href='index.php?page=".$i."'>".$i."</a> ";
} }
// Close MySQL link // Close MySQL link
mysql_free_result($result); require "includes/dbclose.php";
mysql_close($link);
?> ?>

View File

@ -3,6 +3,9 @@
// Include config file // Include config file
require "../includes/config.php"; require "../includes/config.php";
require "../includes/dbconnect.php"; require "../includes/dbconnect.php";
require "../includes/htmlcode.php";
start_html("New post created");
$query = "INSERT INTO blog (date, title, posttext) VALUES $query = "INSERT INTO blog (date, title, posttext) VALUES
@ -18,5 +21,6 @@ print "Post added";
// Close MySQL link // Close MySQL link
mysql_close($link); mysql_close($link);
end_html();
?> ?>

View File

@ -1,6 +1,9 @@
<html><title>Edit post</title> <?php
<body> require "../includes/htmlcode.php";
start_html("Find post to edit");
?>
<h1>Find post to edit</h1>
<form action="editpost.php" method="get"> <form action="editpost.php" method="get">
Date: (YYYY-MM-DD) <input type="date" name="date"> Date: (YYYY-MM-DD) <input type="date" name="date">
<br /><br /> <br /><br />
@ -9,6 +12,6 @@ Title: <input type="text" name="title">
<input type="submit" value="Find post"> <input type="submit" value="Find post">
</form> </form>
<?php
</body> end_html();
</html> ?>

View File

@ -3,7 +3,10 @@
// Include config file // Include config file
require "../includes/config.php"; require "../includes/config.php";
require "../includes/dbconnect.php"; require "../includes/dbconnect.php";
require "../includes/htmlcode.php";
start_html("Edit post");
print "<h1>Edit post</h1>";
$query = "SELECT * FROM blog WHERE date='$_GET[date]' AND title='$_GET[title]'"; $query = "SELECT * FROM blog WHERE date='$_GET[date]' AND title='$_GET[title]'";
$result = mysql_query($query) $result = mysql_query($query)
@ -24,13 +27,15 @@ Text: <br />
<textarea cols='50' rows='10' name='post'>$line[posttext]</textarea> <textarea cols='50' rows='10' name='post'>$line[posttext]</textarea>
<br /> <br />
<input type='submit' value='Update post'> <input type='submit' value='Update post'>
</form>"; </form>
<hr width='50%' align='left'>
<br />";
} }
// Close MySQL link // Close MySQL link
mysql_free_result($result); require "../includes/dbclose.php";
mysql_close($link);
end_html();
?> ?>

View File

@ -1,13 +0,0 @@
<html><title>simplog user interface</title>
<body>
<h1>simplog user interface</h1>
<p>
<a href="newpost.html">Create new post</a>
</p>
<p>
<a href="editpost.html">Edit existing post</a>
</p>
</body>
</html>

16
user/index.php Normal file
View File

@ -0,0 +1,16 @@
<?php
require "../includes/htmlcode.php";
start_html("simlog user interface");
?>
<h1>simplog user interface</h1>
<p>
<a href="new.php">Create new post</a>
</p>
<p>
<a href="edit.php">Edit existing post</a>
</p>
<?php
end_html();
?>

View File

@ -1,6 +1,9 @@
<html><title>Create a new post</title> <?php
<body> require "../includes/htmlcode.php";
start_html("Create new post");
?>
<h1>Create new post</h1>
<form action="createpost.php" method="post"> <form action="createpost.php" method="post">
Date: (YYYY-MM-DD) <input type="date" name="date"> Date: (YYYY-MM-DD) <input type="date" name="date">
<br /> <br />
@ -12,5 +15,6 @@ Text: <br />
<input type="submit" value="Create post"> <input type="submit" value="Create post">
</form> </form>
</body> <?php
</html> end_html();
?>

View File

@ -3,6 +3,9 @@
// Include config file // Include config file
require "../includes/config.php"; require "../includes/config.php";
require "../includes/dbconnect.php"; require "../includes/dbconnect.php";
require "../includes/htmlcode.php";
start_html("Post updated");
$query = "UPDATE blog SET date='$_POST[date]', title='$_POST[title]', $query = "UPDATE blog SET date='$_POST[date]', title='$_POST[title]',
@ -18,5 +21,6 @@ print "Post updated";
// Close MySQL link // Close MySQL link
mysql_close($link); mysql_close($link);
end_html();
?> ?>