Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-15-2005, 06:10 PM   #1 (permalink)
sswong98
Registered User
 
Join Date: Jan 2005
Posts: 4
sswong98 is on a distinguished road
Fatal error: Call to a member function on a non-object

Hello,

I am new to PHP, and am encountering this error at the last line:

include_once('db_inter.php');
include_once('header.php');
$handle = db_connect();

$pages_sql = 'select * from pages order by code';
$pages_result = $handle -> query($pages_sql);

The function db_connect() is located in db_inter.php. The PHP version is 4.3.8. I think the code written for PHP5, and may not be compatible. Could someone confirm?
sswong98 is offline   Reply With Quote
Old 01-15-2005, 07:38 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
is it a mysql database? is db_inter.php a dabase class?
__________________
Mike
sde is offline   Reply With Quote
Old 01-15-2005, 09:23 PM   #3 (permalink)
sswong98
Registered User
 
Join Date: Jan 2005
Posts: 4
sswong98 is on a distinguished road
sorry... yes mysql version 3.23.58
sswong98 is offline   Reply With Quote
Old 01-16-2005, 08:44 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
well, i'm not familiar with the database class you are using, but i suggest you become familiar with the php/mysql functions by themselves.

start off by making a connect script. you can use this script in any web app you use and just change the connection variables. i would put your includes in their own folder. here is what a connection script might look like:
PHP Code:
<?
$hostname
="localhost";
$mysql_login="myusername";
$mysql_password="mypassword";
$database="mydbname";


if (!(
$db mysql_connect("$hostname""$mysql_login" "$mysql_password"))) {
print(
"Can't connect to database.");    
} else {
    if (!(
mysql_select_db("$database",$db))) {
    print(
"Can't connect to table.");
    }
}
?>
ok, now i'll use your example above to query and print the results to the screen.
PHP Code:
<?
// the connect script i made above is named
// connect.php and resides in the inc/ directory.
include("inc/connect.php");

// let's put your header.php in the same directory
// just to keep your file structure neat and tidy
include("inc/header.php");

// here is how you execute a query
$result mysql_query("select * from pages order by code");

// now we can loop through the results and print to the browser
// i don't know the field names of your database table, so i'll make some up
while($row mysql_fetch_array($result)){
  echo 
"Code: " $row['code'] . "<br>\n";
  echo 
"Name: " $row['name'] . "<br>\n";
  echo 
"Text: " $row['text'] . "<br><hr>\n";
}

// now close the mysql connection
mysql_close();
?>
hope that helps.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fatal error: Call to a member function on a non-object CrossMediaGroup PHP 2 11-28-2004 03:46 PM
operate overloading member function in C# sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 03:36 AM
C# member function sureshkumar_kc MS Technologies ( ASP, VB, C#, .NET ) 2 10-15-2004 03:08 AM


All times are GMT -8. The time now is 07:19 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting