Updated a couple things
Index now displays posts properly, gives links to individual posts
Post.php displays each post individually
Postr.php allows you to upload an image and assign it to use it on the Index page
Now using
http://www.geekygents.com/INDEX
Code
<!DOCTYPE HTML>
<html>
<head>
<title>Geeky Gents</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php
SESSION_START();
{
mysql_connect ('localhost', 'root', '');
mysql_select_db ('admin');
}
?>
<div class="links">
<a href="index.php">Home</a>
<a href="about.html">About</a>
<a href="products.html">Products</a>
<a href="join.html">Join Us</a>
</div>
<div class="body">
<?php
if(isset($_SESSION['username']))
{
echo '<p id="make_post"><a href="postr52.php">Make Post</a></p>';
}
$blog_postnumber = 10;
if (!isset($_GET['page']) || !is_numeric($_GET['page'])) {
$page = 1;
}
else {
$page = (int)$_GET['page'];
}
$from = (($page * $blog_postnumber) - $blog_postnumber);
$sql = "SELECT * FROM posts ORDER BY timestamp DESC LIMIT $from, $blog_postnumber";
$result = mysql_query($sql) or print ("Can't select entries from table.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$date = date("F j Y", $row['timestamp']);
$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$id = stripslashes($row['id']);
$image = stripslashes($row['image']);
?>
<div id="post" style="background-image:url(<?php echo $image; ?>);background-repeat:no-repeat;">
<p><a href="/post.php?id=<?php echo $id; ?>"><?php echo $title; ?> <?php echo $date; ?></a></p>
</div>
<?php
}
?>
<div class="page">Page
<?php
$total_results = mysql_fetch_array(mysql_query("SELECT COUNT(*) AS num FROM posts"));
$total_pages = ceil($total_results['num'] / $blog_postnumber);
if ($page > 1) {
$prev = ($page - 1);
echo "<a href=\"?page=$prev\">< </a> ";
}
for($i = 1; $i <= $total_pages; $i++) {
if ($page == $i) {
echo "$i ";
}
else {
echo "<a href=\"?page=$i\">$i</a> ";
}
}
if ($page < $total_pages) {
$next = ($page + 1);
echo "<a href=\"?page=$next\"> ></a>";
}
?>
</div>
</div>
<div class="footer">
<a href="http://www.youtube.com/user/GeekyGents/" target="_blank"><img src="images/icon/yt.png" /></a>
<a href="http://www.facebook.com/GeekyGents/" target="_blank"><img src="images/icon/fb.png" /></a>
<a href="https://twitter.com/GeekyGents/" target="_blank"><img src="images/icon/twitter.png" /></a>
</div>
</body>
</html>
POST
Code
<!DOCTYPE HTML>
<html>
<head>
<title>Geeky Gents</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php
SESSION_START();
{
mysql_connect ('localhost', 'root', '');
mysql_select_db ('admin');
}
?>
<div class="links">
<a href="index.php">Home</a>
<a href="about.html">About</a>
<a href="products.html">Products</a>
<a href="join.html">Join Us</a>
</div>
<div class="body">
<?php
$id = (int)$_GET['id'];
if(isset($_SESSION['username']))
{
echo '<p id="make_post"><a href="updatr52.php?id=',$id,'">Edit Post</a></p>';
}
$result = mysql_query ("SELECT * FROM posts WHERE id='$id'") or print ("Can't select entry.<br />" . $sql . "<br />" . mysql_error());
while ($row = mysql_fetch_array($result)) {
$timestamp = $row['timestamp'];
$title = stripslashes($row['title']);
$entry = stripslashes($row['entry']);
$title = str_replace('"','\'',$title);
$entry = str_replace('<br />', '', $entry);
$month = date("F",$timestamp);
$date = date("d",$timestamp);
$year = date("Y",$timestamp);
$time = date("H:i",$timestamp);
}
?>
<?php echo "<p>", $title, "<br />", $month, " ", $date, " ", $year, "</p>"; ?>
<p><?php echo $entry; ?></p>
</div>
<div class="footer">
<a href="http://www.youtube.com/user/GeekyGents/" target="_blank"><img src="images/icon/yt.png" /></a>
<a href="http://www.facebook.com/GeekyGents/" target="_blank"><img src="images/icon/fb.png" /></a>
<a href="https://twitter.com/GeekyGents/" target="_blank"><img src="images/icon/twitter.png" /></a>
</div>
</body>
</html>
POSTR
Code
<?php
session_start();
if(isset($_SESSION['username']))
{
mysql_connect ('localhost', 'root', '');
mysql_select_db ('admin');
}
else
{
header("Location: index.php");
}
if (isset($_POST['submit'])) {
$month = htmlspecialchars(strip_tags($_POST['month']));
$date = htmlspecialchars(strip_tags($_POST['date']));
$year = htmlspecialchars(strip_tags($_POST['year']));
$time = htmlspecialchars(strip_tags($_POST['time']));
$title = htmlspecialchars(strip_tags($_POST['title']));
$entry = $_POST['entry'];
$image = htmlspecialchars(strip_tags($_POST['uploaded_file']));
$timestamp = strtotime($month . " " . $date . " " . $year . " " . $time);
$entry = nl2br($entry);
if (!get_magic_quotes_gpc()) {
$title = addslashes($title);
$entry = addslashes($entry);
}
$sql = "INSERT INTO posts (timestamp,title,entry,image) VALUES ('$timestamp','$title','$entry','$image')";
$result = mysql_query($sql) or print("Can't insert into table.<br />" . $sql . "<br />" . mysql_error());
mysql_close();
header("location: index.php");
}
$current_month = date("F");
$current_date = date("d");
$current_year = date("Y");
$current_time = date("H:i");
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Geeky Gents</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="links">
<a href="index.php">Home</a>
<a href="about.html">About</a>
<a href="products.html">Products</a>
<a href="join.html">Join Us</a>
</div>
<div class="body">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p>
<input type="hidden" value="<?php echo $current_month; ?>" name="month" id="month" />
<input type="hidden" name="date" id="date" size="2" value="<?php echo $current_date; ?>" />
<input type="hidden" value="<?php echo $current_year; ?>" name="year" id="year" />
<input type="hidden" name="time" id="time" size="5" value="<?php echo $current_time; ?>" /></p>
<p><label for="title">*Title:</label><input type="text" name="title" name="title" size="40" /></p>
<p>*Image:<input type="text" name="uploaded_file" name="uploaded_file" size="70" /></p>
<p>*Content:</p>
<p><textarea cols="80" rows="20" name="entry" id="entry"></textarea></p>
<p>
<input type="submit" name="submit" id="submit" value="Submit">
<input type="button" value="Cancel" onclick="window.location.href='index.php'">
</p>
</form>
<br /><br />
<p>Image Uploader: (150x750)</p>
<form action="uploader.php" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Upload">
</form>
</div>
<div class="footer">
<a href="http://www.youtube.com/user/GeekyGents/" target="_blank"><img src="images/icon/yt.png" /></a>
<a href="http://www.facebook.com/GeekyGents/" target="_blank"><img src="images/icon/fb.png" /></a>
<a href="https://twitter.com/GeekyGents/" target="_blank"><img src="images/icon/twitter.png" /></a>
</div>
</body>
</html>
UPLOADER
Code
<?php
define("UPLOAD_DIR", "uploads/");
if (!empty($_FILES["myFile"])) {
$myFile = $_FILES["myFile"];
if ($myFile["error"] !== UPLOAD_ERR_OK) {
echo "<p>An error occurred.</p>";
exit;
}
// ensure a safe filename
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]);
// don't overwrite an existing file
$i = 0;
$parts = pathinfo($name);
while (file_exists(UPLOAD_DIR . $name)) {
$i++;
$name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
}
// preserve file from temporary directory
$success = move_uploaded_file($myFile["tmp_name"],
UPLOAD_DIR . $name);
if (!$success) {
echo "<p>Unable to save file.</p>";
exit;
}
// set proper permissions on the new file
chmod(UPLOAD_DIR . $name, 0644);
}
?>
<p>Image uploaded successfully to: http://www.geekygents.com/<?php echo UPLOAD_DIR . $name; ?> </p>
<a href="postr52.php">Continue with post</a>
Tomorrow I'll update the Updatr52.php file to allow for changing the image file, and uploading from there as well.