-2

ive been trying to learn some php and i wanted to make a logger

I get user input, put in into an array and make it into json:

This is the class that gets the info:

<?php
class account_Creation
{

    private $username;
    private $password;
    private $email;

    //user input
    public function user_input()
    {
        $username = 'username';
        $password = "password";
        $email = "email";
        $result_array= compact("username","password", "email");
    }
}

$account_creation= new account_Creation();
$account_creation-> user_input();
$logging= new Logging();
$logging-> json_Translator($result_array);

This is the class that translates it into json:

<?php    
class Logging
{
    public function json_Translator($data)
    {
        echo json_encode($data);
    } 
}

I get the error: Uncaught Error: Class 'Logging' not found How do i show the account creation class where the logging class is? I tried include but that did not work

Dolly Aswin
  • 2,684
  • 1
  • 20
  • 23

2 Answers2

0

Let's simplify

Consider the first as page1.php and the next one page2.php

In the page1.php, the changes are:

<?php
include("page2.php");
class account_Creation
.
.
$logging= new Logging; //The brackets should be removed
.
.

This should remove the

Uncaught Error: Class 'Logging' not found

remedcu
  • 526
  • 1
  • 10
  • 31
0

I fix your issue but suggest you to learn OOP

<?php
class account_Creation
{

private $username;
private $password;
private $email;
public $result_array;

//user input
public function user_input()
{
    $this->username = 'username';
    $this->password = "password";
    $this->email = "email";
    $this->result_array= ["username","password", "email"];
}

}
class Logging
{
        public function json_Translator($data)
    {
        echo json_encode($data);

    }


}
$account_creation= new account_Creation();
$account_creation->user_input();
$logging= new Logging();
$logging->json_Translator($account_creation->result_array);
4EACH
  • 2,132
  • 4
  • 20
  • 28