Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:48:45+00:00 2026-05-25T16:48:45+00:00

I’m kinda confused, I’m new to OOP PHP, so can’t stop my function get

  • 0

I’m kinda confused, I’m new to OOP PHP, so can’t stop my function get empty values.

I have an index.php file where I have:

<?php   
require_once('../../includes/functions.php'); 
require_once('../../includes/database.php');
require_once('../../includes/user.php'); 


$user = new User();
$user->username = 'test';
$user->password = '1234';
$user->firstname = 'test1';
$user->lastname = 'test2';

User::create();

// $user->traceStatement();


?>

I have a User class that extends Databaseobject class:
user.php:

<?php 
require_once('database.php');

class User extends DatabaseObject {

    protected static $tableName = 'users';
    protected static $tableID = 'id';

    public $id;
    public $username;   
    public $password;   
    public $firstname;
    public $lastname;

    public function traceStatement() {
        echo $this->username;   
        echo $this->password;   
        echo $this->firstname;  
        echo $this->lastname;                                   
    }


}

?>

and here’s a snippet of create function from DatabaseObject class:

public function create() {
    global $database;
    $calledClass = get_called_class();
    $class = new $calledClass;      
    $sql = "INSERT INTO ".$calledClass::$tableName." (username, password, firstname, lastname) VALUES ('";
    $sql .= $database->escapeValue($class->username)."', '";
    $sql .= $database->escapeValue($class->password)."', '";
    $sql .= $database->escapeValue($class->firstname)."', '";
    $sql .= $database->escapeValue($class->lastname);
    $sql .= "')";   
    if($database->query($sql)) {
        $cass->id = $database->insert_id();
        return true;
    }else {
        return false;
    }
}

As far as I understand the idea is that

on my index.php file i’m declaring varibales of User class, these info are sent to user.php and I’m also calling create() function from databaseobject class through User:: class, and my info inside variables will be sent to create function.

in the database I’m getting blank fields.

I tried to hardcode the variables inside my user.php – and everything work (first I thought I wasn’t getting data from user.php).

When it worked I thought maybe I’m not gettind data from index.php to user.php but it turned out that when I wrote function traceStatement() – I got back the data in index.php file…

So maybe someone here know what’s my problem, what am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:48:46+00:00Added an answer on May 25, 2026 at 4:48 pm

    Rather thanUser::create();, you should use $user->create().

    And your create() method should change to: ($this is very important in the OOP world)

    public function create() {
        global $database;
        $sql = "INSERT INTO ".static::$tableName." (username, password, firstname, lastname) VALUES ('";
        $sql .= $database->escapeValue($this->username)."', '";
        $sql .= $database->escapeValue($this->password)."', '";
        $sql .= $database->escapeValue($this->firstname)."', '";
        $sql .= $database->escapeValue($this->lastname);
        $sql .= "')";   
        if($database->query($sql)) {
            $this->id = $database->insert_id();
            return true;
        }else {
            return false;
        }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.