R.Bucky Posted April 14, 2009 Share Posted April 14, 2009 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 mark@buckycomputing.net. --> <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 Quote Link to comment https://forums.phpfreaks.com/topic/153946-cannot-display-mysql-variables-for-custom-micro-blog/ Share on other sites More sharing options...
Maq Posted April 14, 2009 Share Posted April 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/153946-cannot-display-mysql-variables-for-custom-micro-blog/#findComment-809102 Share on other sites More sharing options...
R.Bucky Posted April 14, 2009 Author Share Posted April 14, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/153946-cannot-display-mysql-variables-for-custom-micro-blog/#findComment-809105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.