Jump to content

Recommended Posts

Okay, I'm working with 4 main files in this problem. Very small amounts of code. Now, so far profiles.class.php is running a function (create) which requires a function (post) from another file forms.class.php which contains the class forms. Now, Im getting this error:

 

Fatal error: Call to a member function posted() on a non-object in C:\xampp\htdocs\client\extensions\profiles.class.php on line 11

 

profiles.class.php:

<?php

require_once('extensions/forms.class.php');

$forms = new forms;

class profiles {

function create() {

	$result = $forms->post();

	if ($result == false) {

		echo "Complete the fields marked with <span class='main-first'>*</span><span class='content'>";
		echo "<table width='50%' border='0'>";
		echo "<form method='post'>";
		echo "<tr>";
		echo "<td width='25%> Name: </td> <td> <input type='text' name='name'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Email: </td> <td> <input type='text' name='email'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Address: </td> <td> <input type='text' name='address'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Postcode: </td> <td> <input type='text' name='postcode'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Suburb: </td> <td> <input type='text' name='suburb'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Phone Number: </td> <td> <input type='text' name='phone'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Mobile: </td> <td> <input type='text' name='mobile'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%'> <input type='submit' name='submit'> </td> <td> </td>"; 
		echo "</tr>";
		echo "</form>";
		echo "</table>";

	}

}

}

?>

 

forms.class.php:

<?php

class forms {

function post() {

	if (isset($_POST['submit'])) {

		return true;

	}

	else {

		return false;

	}

}

function check($value) {

	if (trim($value) == '') {

		return false;

	}

	else {

		return true;

	}

}

}

?>

 

header.inc.php:

<?php

require_once('extensions/profiles.class.php');

$profiles = new profiles;

?>

<html>

<head>

<title> Wintersword Studios </title>

<link rel="stylesheet" type="text/css" href="extensions/styles/style.css" />

</head>

<body>
<table width='100%' border="0" class='layout'>
<tr>
    	<td>
            <table width="100%" border="0">
            	<tr>
                  <td width='50%' valign='bottom'><span class='title-first'>C</span><span class='title'>MS v1.0</span></td>
                    <td valign='bottom'>
                    <a href='index.php' style="text-decoration:none;"> <span class='main-first'>H</span><span class='main'>ome </span></a> <span class='main'> | </span><a href='terms.php' style='text-decoration:none;'><span class='main-first'>T</span><span class='main'>erms</span></a><span class='main'> | </span><a href='sitemap.php' style='text-decoration:none;'><span class='main-first'>S</span><span class='main'>itemap</span></a><span class='main'> | </span><a href='support.php' style='text-decoration:none;'><span class='main-first'>S</span><span class='main'>itemap</span></a></td>
                </tr>
            </table>
            <table width="100%" border="0">
                <tr>
                    <td> </td>
              </tr>
            </table>
            <table width="100%" border="0" cellpadding='5px'>
                <tr>
                    <td width='22%' class='middle'> <span class='content'> Links: </span></td>
          <td> <span class='content'>

 

index.php:

<?php

require_once('extensions/templates/header.inc.php');

?>

Welcome to Wintersword's CMS. This site is currently version 1.0-Beta. CMS or Client Management System is used to keep
track of information in an ordered and easy to access way. It is mainly used for monitoring entitie's clients but, it 
can be used for many other things. <br /> <br />

Features: <br />
- Creation and manipulation of records <br />
- User permissions <br />
- Search functions <br />

Bugs fixed: <br />
- None <br />

<?php	

require_once('extensions/templates/footer.inc.php');

?>

 

Yeap, thats about all the information I can give without being a bore. Can you please help me with whats wrong?

 

Daniel

 

Link to comment
https://forums.phpfreaks.com/topic/83444-php5-oop-problems/
Share on other sites

The object $forms does not exist within the class profiles. You need to define it within the class itself, no good defining it outside because it is out of scope. eg;

 

<?php

  class forms{}

  class profile {
    private $forms;
    function __construct() {
      $this->forms = new forms; // now the forms object can be accessed within the profile class using $this->forms.
    }
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424521
Share on other sites

Same error, Different line. New code for profiles.class.php:

 

<?php

require_once('extensions/forms.class.php');

class profiles {

private $forms;

function __construct() {
      
	$this->forms = new forms; 
    
}

function create() {

	$result = $forms->post();

	if ($result == false) {

		echo "Complete the fields marked with <span class='main-first'>*</span><span class='content'>";
		echo "<table width='50%' border='0'>";
		echo "<form method='post'>";
		echo "<tr>";
		echo "<td width='25%> Name: </td> <td> <input type='text' name='name'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Email: </td> <td> <input type='text' name='email'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Address: </td> <td> <input type='text' name='address'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Postcode: </td> <td> <input type='text' name='postcode'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Suburb: </td> <td> <input type='text' name='suburb'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Phone Number: </td> <td> <input type='text' name='phone'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%> Mobile: </td> <td> <input type='text' name='mobile'> </td>"; 
		echo "</tr>";
		echo "<tr>";
		echo "<td width='25%'> <input type='submit' name='submit'> </td> <td> </td>"; 
		echo "</tr>";
		echo "</form>";
		echo "</table>";

	}

}

}

?>

 

Thanks, Daniel

 

 

Link to comment
https://forums.phpfreaks.com/topic/83444-php5-oop-problems/#findComment-424527
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.