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

  • SEARCH
  • Home
  • 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 764529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:44:32+00:00 2026-05-14T16:44:32+00:00

What is wrong with this code? <?php class users { var $user_id, $f_name, $l_name,

  • 0

What is wrong with this code?

<?php

class users {

  var $user_id,
      $f_name,
      $l_name,
      $db_host,
      $db_user,
      $db_name,
      $db_table;

  function users() {
      $this->$db_host = 'localhost';
      $this->$db_user = 'root';
      $this->$db_name = 'input_oop';
      $this->$db_table = 'users';
  }

  function userInput($f_name, $l_name) {
      $dbc = mysql_connect($this->db_host , $this->db_user, "") or die ("Cannot connect to database : " .mysql_error());
      mysql_select_db($this->db_name) or die (mysql_error());
      $query = "insert into $this->db_table values (NULL, \"$f_name\", \"$l_name\")";
      $result = mysql_query($query);
      if(!$result) die (mysql_error());

      $this->userID = mysql_insert_id();

      mysql_close($dbc);

      $this->first_name = $f_name;
      $this->last_name = $l_name;
  }

  function userUpdate($new_f_name, $new_l_name) {
      $dbc = mysql_connect($this->db_host, $this->db_user, "") or die (mysql_error());
      mysql_select_db($this->db_name) or die (mysql_error());

      $query = "UPDATE $this->db_table set  = \"$new_f_name\" , \"$new_l_name\" WHERE user_id = \"$this->user_id\"";
      $result = mysql_query($query);

      $this->f_name = $new_f_name;
      $this->l_name = $new_l_name;
      $this->user_id = $user_id;

      mysql_close($dbc);
  }

  function userDelete() {
      $dbc = mysql_connect($this->db_host, $this->db_user, "") or die (mysql_error());
      mysql_select_db($this->db_name) or die (mysql_error());

      $query = "DELETE FROM $this->db_table WHERE $user_id = \"$this->user_id\"";

      mysql_close($dbc);
  } 
}
?>

The error is:

Fatal error: Cannot access empty property in C:\xampp\htdocs\jordan_pagaduan\class.php on line 15.

  • 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-14T16:44:33+00:00Added an answer on May 14, 2026 at 4:44 pm

    To access a class-property from inside a method of a class, you must use $this->propertyName, and not $this->$propertyName.

    Which means your user_input() method should be written like this :

    function user_input() {
        $this->db_host = 'localhost';
        $this->db_user = 'root';
        $this->db_name = 'input_oop';
        $this->db_table = 'users';
    }
    

    (you might have to do the same modification to other places)

    With what you have written, `$this->db_user` is never set ; and, later, when using this :

    $dbc = mysql_connect($this->db_host , $this->db_user, "")
    

    $this->db_user is null ; which means mysql_connect will use the default value — which, in your case, appears to be ODBC, judging from the error message.

    (same thing with the other properties — but I took this one as an example, as the ODBC default-value was present in the error message you posted : it was the most obvious choice.)

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

Sidebar

Related Questions

//this is my code from class.php class Functions { function getUsers($sex) { $stmt =
Can someone tell me what is wrong with this code? <?php $user = $fgmembersite->UserFullName();
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
My code is like this: <?php define(ERROR, SOMETHING WRONG WITH MY DATABASE); ... if
what's wrong with this code in Google Chrome r = webkitIndexedDB.open(db_name,1); r.onsuccess = success_callback;
Whats wrong with this code? -(void) drawRect:(CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); if
Is there anything wrong with this code or can this be done more efficiently?
What's wrong with this code?: SolverContext sc = SolverContext.GetContext(); Model m = sc.CreateModel(); m.AddDecision(new
Why is this code correct: try { } catch(ArrayOutOfBoundsException e) {} and this wrong:
What is wrong with this code. The code is finding the javascript and debug1

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.