Hello,
I am creating a blog: http://adamb10.com/UltraBlog
I am trying to make entries show but they won't Here are 2 files. The 1st file is index.php which grabs the data from mysql database and displays it:
<?
session_start();
include_once("Sources/sys.php");
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>
<?
include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';
$result = mysql_query('SELECT title FROM Userdata') or die("Error: ".mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo $row['title'];
}
echo
'</title>
<link rel="stylesheet" type="text/css" href="http://adamb10.com/UltraBlog/themes/style1.css"/>
</head>';
if($action == "login"){
return('/Sources/sys.php');
}
if($action == "acp"){
return('/Sources/sys.php');
}
if($action == "settings"){
return('/Sources/sys.php');
}
if($action == "about"){
return('/Sources/sys.php');
}
if($action == "addentry"){
return('/Sources/sys.php');
}
if($action == "editprofile"){
return('/Sources/sys.php');
}
if($action == "hf"){
return('/Sources/sys.php');
}
echo
'<body>
<center><table width="80%" cellspacing="1" cellpadding="1" border="0" class="border">
<td class="windowbg2" colspan="4"><center><font size="3"><b>Welcome to'; echo $row['title'];
echo '</b></font></center>
<tr>';
?>
<?
include '/home/adamb10/public_html/UltraBlog/Sources/urls.php';
//Standard stuff that you already know how to do. Make sure you use the @ before mysql_connect though,
// if you don't and there's a problem, your password information will be displayed to everyone, it's
// technically a good idea to write your own wrapper function for this so as to hide it from everyone
// in all cases (ie: like if your host's PHP parsing suddenly died and all PHP were displayed as
// plaintext to the world...you'd be showing your information yet again, for anyone to connect. BAD!
// By the way, the '@' symbol before any pre-written function allow any error messages NOT to be
// displayed. If you use this, be certain you'll never, ever have a problem, or only do it for
// security reasons. You won't want to use this during debugging (except for perhaps this line of
// code, just because it's so simple, we still have the mysql_error function printing on error,
// and something else I can't think of. :)
//Replace 'server' with your MySQL server location information, 'username' with your database server's
// username for access, and password with your database server's password. If you're using a different
// database type (i.e.: Microsoft SQL Server), you will have to change the functions to suit your needs.
// The SQL should still work, except for the LIMIT clause suggested within a comment - it is a MySQL
// proprietary function.
include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';
//We needed to select the database that we'd be using...again, standard process.
//mysql_select_db('adam', $cnx) or die('Could not connect to database: ' . mysql_error());
//This SQL select statement will gather all information we should need for displaying your blog entries,
// I use Entrys.Id and Userdata.Id here because when two tables contain the same field name, MySQL has
// no idea which field belongs to which table. We always use the tablename first, then the field in dot
// notation. Since the other fields do not have the same names, we can refer to them as normal.
// I used the WHERE clause so that MySQL knows which blog entries are associated with which author, and
// vice-versa. I used the ORDER BY clause to make sure that we get the most recent entries first, as
// most blogs that I've seen show the most recent entries first... If you want to change this, switch DESC
// to ASC or vice-versa. You can play around with those yourself.
$sql = 'SELECT entrys.Id, entrys.Date, entrys.Title, entrys.Entries, Userdata.Email FROM entrys, Userdata WHERE entrys.UserID=Userdata.Id ORDER BY Date DESC';
//Time to actually run the SQL statement - it was only created on the above line (I think it's easier this way)
$result = mysql_query($sql) or die(mysql_error());
//Now we want to break down this information into useable variables for display purposes...
// However, we need to use a loop because the information stored in $result is something called a mysql
// result resource (unless I'm thinking of $cnx)...anyhow, it's in an object/array style format and we
// only want a portion at a time to work with, since ALL stories and users are returned. Then we'll go
// ahead and display each one separately.
while($blog = mysql_fetch_array($result)){
//I like to use "mysql_fetch_array", but there are many options to this, however, if you decide to use
// a different method, the below code will have to be altered...
$date = $blog['Date'];
$title = $blog['Title'];
$entry = $blog['Entries'];
//$user = $blog['Username'];
$email = $blog['Email'];
//this file is described below, it handles the displaying of the actual information
// the hard part, querying the database and gathering all the information, is done.
// If you ever want to only display the first so many entries at one time, there is
// a clause that you can add to the SQL query above to do so, just add (I believe)
// the LIMIT clause, and follow it with a number, such as:
// SQL CODE: [...] LIMIT 10
// It's easiest just to add it to the end. Change "10" to whatever number you'd want.
include 'templates/entry.php';
}
?>
<br><br><br><br>
<br>
<------FOOTER------>
<br><br><br><br><br><br><br>
<? include 'copyright.html'; ?>
</body>
</html>
Here is the template file thats gets included in index.php toward the end of the file:
<?php
include '/home/adamb10/public_html/UltraBlog/Sources/mysqlconnect.php';
//This file contains the HTML used as a template for each entry so that you can easily
// change the formatting of your entries, whenever you wish. If you get fancy, you can
// create a web-based interface that can access this file and update the informtion
// contained in it and auto-"magically", all of your entries have a new look. :)
//The only things that are not HTML are the PHP variables that are being printed within the template. If you do not have short-tags turned on in your PHP ini file, you
// will have to change the <?=$variable to <?php echo $variable; . Technically, the
// latter is better, but for looks, and for those who don't understand PHP, the smaller
// things are, the better.
?>
<table width="80%" cellspacing="1" cellpadding="1" border="0" class="border">
<tr>
<th class="titlebg"><?=$title?></th>
<th class="titlebg" width="145"><?=$date?></td>
</tr>
<tr>
<td class="titlebg" colspan="2"><?=$entry?></td>
</tr>
</table><p />
I've been trying to figure this out for about a month and am anxious to get this fixed.
Thanks!
Adam