Split it up a bit more and added a way to find and edit posts
This commit is contained in:
parent
4847b5f4d7
commit
387012735f
11
includes/dbconnect.php
Normal file
11
includes/dbconnect.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
// Connect to MySQL database
|
||||
$link = mysql_connect($host, $user, $password)
|
||||
or die("Could not connect...");
|
||||
|
||||
mysql_select_db($database)
|
||||
or die("Could not open database");
|
||||
|
||||
|
||||
?>
|
11
index.php
11
index.php
@ -1,14 +1,9 @@
|
||||
<?php
|
||||
|
||||
// Include config file
|
||||
require "config.php";
|
||||
// Include config file and other include-files
|
||||
require "includes/config.php";
|
||||
require "includes/dbconnect.php";
|
||||
|
||||
// Connect to MySQL database
|
||||
$link = mysql_connect($host, $user, $password)
|
||||
or die("Could not connect...");
|
||||
|
||||
mysql_select_db($database)
|
||||
or die("Could not open database");
|
||||
|
||||
// Divide the posts into pages, N number of posts on every page
|
||||
if (isset($_GET["page"]))
|
||||
|
@ -1,14 +1,8 @@
|
||||
<?php
|
||||
|
||||
// Include config file
|
||||
require "../config.php";
|
||||
|
||||
// Connect to MySQL database
|
||||
$link = mysql_connect($host, $user, $password)
|
||||
or die("Could not connect...");
|
||||
|
||||
mysql_select_db($database)
|
||||
or die("Could not open database");
|
||||
require "../includes/config.php";
|
||||
require "../includes/dbconnect.php";
|
||||
|
||||
|
||||
$query = "INSERT INTO blog (date, title, posttext) VALUES
|
||||
|
14
user/editpost.html
Normal file
14
user/editpost.html
Normal file
@ -0,0 +1,14 @@
|
||||
<html><title>Edit post</title>
|
||||
<body>
|
||||
|
||||
<form action="editpost.php" method="get">
|
||||
Date: (YYYY-MM-DD) <input type="date" name="date">
|
||||
<br />
|
||||
Title: <input type="text" name="title">
|
||||
<br />
|
||||
<input type="submit" value="Find post">
|
||||
</form>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
36
user/editpost.php
Normal file
36
user/editpost.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
// Include config file
|
||||
require "../includes/config.php";
|
||||
require "../includes/dbconnect.php";
|
||||
|
||||
|
||||
$query = "SELECT * FROM blog WHERE date='$_GET[date]' AND title='$_GET[title]'";
|
||||
$result = mysql_query($query)
|
||||
or die("No matching queries...");
|
||||
|
||||
|
||||
// Printing posts in HTML
|
||||
while ($line = mysql_fetch_array($result))
|
||||
{
|
||||
print "
|
||||
<form action='updatepost.php' method='post'>
|
||||
Post number: <input type='text' name='postnumber' value='$line[postnumber]' readonly><br />
|
||||
Date: (YYYY-MM-DD) <input type='date' name='date' value='$line[date]'>
|
||||
<br />
|
||||
Title: <input type='text' name='title' value='$line[title]'>
|
||||
<br /><br />
|
||||
Text: <br />
|
||||
<textarea cols='50' rows='10' name='post'>$line[posttext]</textarea>
|
||||
<br />
|
||||
<input type='submit' value='Update post'>
|
||||
</form>";
|
||||
}
|
||||
|
||||
|
||||
// Close MySQL link
|
||||
mysql_free_result($result);
|
||||
mysql_close($link);
|
||||
|
||||
|
||||
?>
|
@ -9,7 +9,7 @@ Title: <input type="text" name="title">
|
||||
Text: <br />
|
||||
<textarea cols="50" rows="10" name="post"></textarea>
|
||||
<br />
|
||||
<input type="submit">
|
||||
<input type="submit" value="Create post">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
22
user/updatepost.php
Normal file
22
user/updatepost.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// Include config file
|
||||
require "../includes/config.php";
|
||||
require "../includes/dbconnect.php";
|
||||
|
||||
|
||||
$query = "UPDATE blog SET date='$_POST[date]', title='$_POST[title]',
|
||||
posttext='$_POST[post]' WHERE postnumber='$_POST[postnumber]'";
|
||||
|
||||
if (!mysql_query($query))
|
||||
{
|
||||
die ("Something went wrong!");
|
||||
}
|
||||
print "Post updated";
|
||||
|
||||
|
||||
// Close MySQL link
|
||||
mysql_close($link);
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user