Jump to content

Cannot display MySQL variables for custom micro-blog


R.Bucky

Recommended Posts

Hello all -

I host an Ubuntu LAMP Server 8.04. Trying to code a second variant of my micro-blog. My installation script writes to a file database.php with the following configuration:

<?php 
$active_group = "default";
$db['default']['hostname'] = "localhost";
$db['default']['database'] = "microBucky";
$db['default']['username'] = "root";
$db['default']['password'] = "password";
?>

I want to display the content from the three columns in my table, which are title, body_text, and created. I have gone through several code variants for the index.php to display my content. Can someone help me out? Displaying content using the mysqli_connect() info at the top of the page. But, I want to use the remote file database.php that my install script created to connect. Here is what I have so far for my index.php

 

<?
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
include_once('add_entry/entry.php');
include_once('config/database.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
microBucky2 is created by Mark Moore at http://buckycomputing.net. All inquiries can be forwarded to [email protected].
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>microBucky2</title>
<link rel="stylesheet" type="text/css" href="appearance.css" />
</head>

<body>
<div id="page-wrap">
<?php
$sql = "SELECT title, microBucky FROM microBucky";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
echo $row['title'].'<br />';
echo $row['body_text'].'<br />';
echo $row['created'].'<br />';
echo 'Last modified: ';echo date ('g:i a, j M Y',getlastmod());}
?>

 

~Mark

First, always use <?php, never short-tags, it minimizes portability.

 

Second, I fail to see where you try to use this file.

 

You're using:

 

$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);

 

in which all these variables are undefined, not to mention that your include file is below the code that needs to use it.

Good points you make. I have tried so many code variants, I am jumbled. Fairly new to writing code - but, you knew that. The file listed above is used for displaying posts with data from MySQL in a microBlog type of format. Can anyone suggest a correct method of querying connection data from my database.php file?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.