Zend - The PHP Company




Utilities

Add Code


Simple diary / News / Journal system  

Type: application
Added by: sunnyhundal
Entered: 01/05/2001
Last modified: 05/12/2000
Rating: - (fewer than 3 votes)
Views: 7666
My application lets you write a keep a simle database driven diary / journal / news system on your website. Its mysql driven, and very easy to set up and install.


reademe for mydiary 1.0

- description of files :
    + index.php : this is the main page where your diary gets displayed. it has all the code to grab your diary entries from the database.
    + common.php : has all the database and main variables you need to edit. you cannot use the diary without editing this file!
    + add.php : go to this page to add your diary entry. it also has the code to insert the entry into your database.
    + database.sql : this contains the sql to make a table for your diary. you can either type it out into your mysql prompt or do something 
    like this when you telnet to your server - 
        mysql -h(mysql_host_address) -u(your_username) -p(yourpassword) (database name) < ./database.sql 
        but you have to make sure that you are currently in the directory where database.sql file resides, otherwise it wont be able to find the file to create the table.
         
installation of this diary is very simple. if you have any problems, you are welcome to leave questions at my php mini-forum at :
http://www.wde.org/me/php/ and i'll try and help you out.

- unpack all the files into a folder, something like : "http://www.yourhomepage.com/mydiary/"
- make the table in your database using file "database.sql".
- go to the folder where you unpacked the files using your browser! nice and simple. :) 
- test it out by addig your entry by first going to add.php

good luck!


/sunny
sunny@wde.org 
*****************************************************

The add.php file to add a new entry
----------------------------------
<?

if ($addtodiary) {

    include(
"common.php");
    
    
MYSQL_CONNECT($hostname,$username,$passwrd) OR DIE("Couldnt connect to the database, sorry mate!");
    @
mysql_select_db($dbName) or die( "Unable to select database"); 
    
    
$month date("F");
    
$thedate date(" l, jS F");

    
$query "INSERT into $tablename values (NULL,'$thedate','$month','$topic','$entry')";
    
$result mysql_query($query);
    
header ("Location: $domain/index.php"); 

//    echo "<font color=red>".mysql_error()."</font>";  //get rid of the beginning slashes if you get errors, this will tell you why.
mysql_close;
}

else { echo 
"

<html>
<head>
    <title>My Diary</title>
</head>

<body bgcolor="
ffffff" text="000000">

<form action="
add.php" method="post">
<table align=center cellspacing=10>
<tr>
    <td colspan=2>
        <hr color="
990000" size="2" noshade width="100%">
        <h1>Add an entry to the diary </h1>
    </td>
</tr>

<tr>
    <td align=right><strong>the topic: </strong></td>
    <td><input type="
text" name="topic" size="50" maxlength="50"></td>
</tr>

<tr>
    <td align=right valign=top><strong>diary entry</strong></td>
    <td><textarea cols="
50" rows="10" name="entry"></textarea></td>
</tr>

<tr>
    <td colspan="
2" align="center"><input type="submit" name="addtodiary"><br>
        <hr color="
990000" size="2" noshade width="100%"></td>
</tr>
</table>
</form>

</body>
</html> "

}
?>
********************************************************



The index.php file to display the data
--------------------------------------
<html>
<head>
    <title>My Diary</title>
</head>

<script language="JavaScript">
function GoUrl(s)
{       var d = s.options[s.selectedIndex].value
        window.top.location.href = d
        s.selectedIndex=0
}
</script>

<?
    
include ("common.php");
    
    if (empty(
$month)) {
    
$month gmdate("F(Y)"); 
    }

    
MYSQL_CONNECT($hostname,$username,$passwrd) OR DIE("Couldnt connect to the database, sorry mate!");
    @
mysql_select_db($dbName) or die( "Unable to select database"); 

    
$query " SELECT thedate, topic, entry FROM $tablename WHERE month='$month' ORDER BY id desc";
    
$result mysql_query($query);

    if (
$result) {
    echo 
"<table border=0 cellspacing=0 cellpadding=2 width=$width align=center>";
    
    while (
$r mysql_fetch_array($result)) {
    
extract($r);

    
$entry nl2br($entry);

    echo 
"  
            <tr bgcolor=#ffffff><td><strong class=black-small>
$topic</strong></td><td align=right><strong class=black-small>$thedate</strong></td></tr>
            <tr bgcolor=#ffffff><td colspan=2><small class=black-small>
$entry</small><br><hr color=990000 size=1 width=100%></td></tr>
                "
;
        }
}

mysql_free_result($result);

    
$query2 "SELECT month FROM $tablename GROUP BY month ORDER BY id";
    
$result2 mysql_query($query2);
    if (
$result2) {
    echo 
"<tr><form>
                <td align=right colspan=2 valign=top>
                        <select onchange="
GoUrl(this)"> 
                            <option> previous diary entries for:"
;
                                while (
$r2 mysql_fetch_array($result2)) {
                                
extract($r2);
                                echo 
"
                                <option> &nbsp;
                                <option value=index.php?month=
$month><strong class=black-small> -&gt; &nbsp; $month </strong>";
                                }
                        echo 
"</select>
                </td></form>
            </tr></table> "
;
    }
    else {
        echo 
"<strong class=black>Whoops! Something wrong happened to the my database! </strong>";
    }
mysql_free_result($result2);
    
exit();    

?>
</body>
</html>
********************************************************



The common.php file for storing variables
----------------------------------------
<?

$domain 
"http://www.yoursite.com";  //replace with the full url to where the index file while be located. 
                                                            //dont trail with a slash and leave no spaces at the end!

$hostname "mysql.yoursite.com";  //hostname of your database 
$dbName "dbname"// name of the database you will use
$username "username"// username to access your database
$passwrd "password";  // password to access your database
$tablename "mydiary"// the name of the table which will contain your diary entries
    
$width "80%";      // width of the html table on the front page which displays your diary.

?>
*****************************************************



creating the table in your database:
CREATE TABLE mydiary (
   id smallint(6) NOT NULL auto_increment,
   thedate varchar(35),
   month varchar(20),
   topic varchar(50),
   entry text,
   PRIMARY KEY (id)
);
*****************************


Usage Example


See the example


Rate This Script





Search



This Category All Categories