Hi I am having a problem with this script the date does'nt display properly and I am unable to read what I entered it is a web log script for keeping an online journal I was wondering if someone could take a look at it to tell me whats wrong
There is more to it but I believe the problem is in here
Thank you
Note you can view what its supposed to do at http://theartists.ca/Weblog/db_weblog.php
Here it is:
<?php
/* This page has 5 possible cases:
1. You got to this page by following a link, so a date is supplied. This is neither the first nor the last entry in the db.
You got to this page by following a link, so a date is supplied. This is the first entry in the db.
You got to this page by following a link, so a date is supplied. This is the last entry in the db.
You're viewing this page without a supplied date (so default to today's date), and there is a fresh entry for today.
You're viewing this page without a supplied date (so default to today's date), and there's no fresh entry. Give a default message with link to the last entry.
*/
/ Get today's date for Cases 4 and 5. /
if(!IsSet($date))
{
$date = date("Ymd");
}
?>
<HTML>
<HEAD>
<TITLE>PHP4 weblog: <?php print("$date"); ?></TITLE>
</HEAD>
<BODY BGCOLOR=#FFFFFF>
<TABLE BORDER="0" CELLPADDING="5" WIDTH=100%>
<tr>
<td><?php include("topnav.htm"); ?></td></tr>
<TR BGCOLOR=#CC3300>
<TD ALIGN=RIGHT><h3>My weblog for <?php print("$date"); ?></h3>
</TD></TR>
<TR><TD>
<TD WIDTH=750>
<?php
/ Open database connection. /
include("db_password.php");
mysql_connect($hostname, $user, $password);
mysql_select_db("update_webupdates");
/ Identify the last entry for Cases 3, 4, and 5. /
$query = ("SELECT MAX(ID) FROM mylog");
$result = mysql_query($query);
$lastID_row = mysql_fetch_array($result);
$last_ID = $lastID_row[0];
/ The first branch of this test displays weblog entries in Cases 1 - 4... /
$query1 = ("SELECT ID, logtext FROM mylog WHERE date = $date");
$result1 = mysql_query($query1);
$row_test_num = mysql_num_rows($result1);
if($row_test_num > 0)
{
$entry_row = mysql_fetch_array($result1);
$entry_ID = $entry_row[0];
$logtext = stripslashes($entry_row[1]);
/* Gets Previous date for Cases 1, 3, and 4. This test assumes a database that auto-increments from 1; if this is not the case, you need to change the integer below. */
if($entry_ID > 1)
{
$prev_ID = $entry_ID - 1;
$query2 = ("SELECT date FROM mylog WHERE ID = $prev_ID");
$result2 = mysql_query($query2);
$prevdate_row = mysql_fetch_array($result2);
$prev_date = $prevdate_row[0];
}
else
{
$prev_date = "";
}
/* Gets Next date for Cases 1 and 2. */
if($entry_ID != $last_ID)
{
$next_ID = $entry_ID + 1;
$query3 = ("SELECT date FROM mylog WHERE ID = $next_ID");
$result3 = mysql_query($query3);
$nextdate_row = mysql_fetch_array($result3);
$next_date = $nextdate_row[0];
}
else
{
$next_date = "";
}
/ Output text for... /
/ Case 1 /
if($next_date != "" && $prev_date != "")
{
print("<CENTER><P><A HREF=\"db_weblog.php?date=$next_date\">Next</A> <A HREF=\"db_weblog.php?date=$prev_date\">Previous</A></P></CENTER>\n$logtext\n<CENTER><P><A HREF=\"db_weblog.php?date=$next_date\">Next</A> <A HREF=\"db_weblog.php?date=$prev_date\">Previous</A></P></CENTER>");
}
/ Case 2 /
elseif($next_date != "" && $prev_date == "")
{
print("<CENTER><P><A HREF=\"db_weblog.php?date=$next_date\">Next</A></P></CENTER>\n$logtext\n<CENTER><P><A HREF=\"db_weblog.php?date=$next_date\">Next</A></P></CENTER>");
}
/ Cases 3 and 4. /
elseif($next_date == "" && $prev_date != "")
{
print("<CENTER><P><A HREF=\"db_weblog.php?date=$prev_date\">Previous</A></P></CENTER>\n$logtext\n<CENTER><P><A HREF=\"db_weblog.php?date=$prev_date\">Previous</A></P></CENTER>");
}
}
/ ...while this branch covers Case 5. /
else
{
/ Get the date of last entry. /
$query2 = ("SELECT date FROM mylog WHERE ID = $last_ID");
$result2 = mysql_query($query2);
$lastdate_row = mysql_fetch_array($result2);
$last_date = $lastdate_row[0];
print("<P>Sorry, nothing new today! My last entry is <A HREF=\"db_weblog.php?date=$last_date\">here</A>.</P>");
}
?>
</TD></TR>
</TABLE>
</TD></TR>
</TABLE>
</BODY>
</HTML>