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 1030857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:50:15+00:00 2026-05-16T13:50:15+00:00

I might be missing something here, I’m not sure. A Google search didn’t really

  • 0

I might be missing something here, I’m not sure. A Google search didn’t really help either.

What I’m wanting to do is call the databaseServer class and use its methods within my userControl class. Here is my lib_class.php file:

<?php

include('definitions.php');

class databaseServer {

    var $con;
    var $db;
    var $close;
    var $qry;
    var $sql;

    function connect($host,$user,$pw,$db) {
        $this->con = mysql_connect($host,$user,$pw);
        if (!$this->con) {
            die('Could not connect: ' . mysql_error());
            }
        else {
            echo "Database Connected";
            }
        $this->selectDb($db);
        }

    function selectDb($database) {
        $this->db = mysql_select_db($database,$this->con);
        if (!$this->db) {
            echo "Could not Select database";
            }
        else {
            echo "Database Selected";
            }
        }

    function disconnect() {
        $this->close = mysql_close($this->con);
        if ($this->close) {
            echo "Disconnected";
            }
        }

    function query($test) {
        if (!mysql_query($test)) {
            die("Error: " . mysql_error());
            }
        }

} // databaseServer

class cookie {

    var $expireTime;

    function set($name,$value,$expiry) {
        $this->expireTime = time()+60*60*24*$expiry;
        setcookie($name,$value,$expireTime);
        }

    function delete($name) {
        setcookie($name,"",time()-3600);
        }

    function check($name) {
        if (isset($_COOKIE["$name"]))
            echo "Cookie Set";
        else
            echo "Cookie failed";
        }

} //cookie

class userControl {

    public function __construct(databaseServer $server) {
        $this->server = new databaseServer();
    }

    function createUser($uname,$pword) {

        $this->server->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $result = $this->server->query("SELECT * FROM user_list WHERE uname='" . $this->server->real_escape_string($uname) . "'");
        if ($this->result->num_rows() === 0) {

            if ($this->server->query("INSERT INTO user_list (uname, pword) 
            VALUES ('" . $this->server->real_escape_string($uname) . "','" . $this->server->real_escape_string($pword) . "')") {
                echo "User Added Successfully!";
            }
            else {
                echo "Error Adding User!";
            }
        }

        else {
            echo "User Already Exists!";
        }

    } // createUser

} // userControl

?>

However, this isn’t working and I can’t see why. My databaseServer and cookie classes work fine when I omit the userControl class from the file, so I know the error must be in that class somewhere. OOP is something I’m trying to learn and I keep stumbling.

The echoes in the databaseServer class are there only for me to test it. I am implementing the classes in an index.php file as follows:

<?php

include('definitions.php');
include('class_lib.php');

$bmazed = new databaseServer();

$bmazed->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);

$sql = "INSERT INTO blah
VALUES ('testing 92')";

$bmazed->query($sql);

$bmazed->disconnect();

// $control = new userControl();

// $uname = "Test1";
// $pword = "test1";

// $control->createUser($uname,$pword);

echo "<br />";
echo "<br />";

?>

Lines have been commented out for testing purposes, so I don’t have to keep re-writing code.

I really have no idea where the problem lies, I’ve checked syntax and everything seems fine.

  • 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-16T13:50:15+00:00Added an answer on May 16, 2026 at 1:50 pm

    Initialize $server in the constructor:

    class userControl {
    
     private $server;
    
     function __construct() {
      $this->server = new databaseServer();
     }
    
     function createUser($uname,$pword) {
      $this->server->connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
      $result = $this->server->query("SELECT * FROM user_list WHERE uname='" . $this->server->real_escape_string($uname) . "'");
      if ($this->result->num_rows() === 0) {
    
       if ($this->server->query("INSERT INTO user_list (uname, pword) VALUES ( '" . $this->server->real_escape_string($uname) . "','" . $this->server->real_escape_string($pword) . "')") {
        echo "User added Succesfully";
        }
       else {
        echo "Error Adding User";
        }
    
      else {
       echo "User already exists";
       }
     }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be missing something here because I thought this might be really easy
I might be missing something really obvious. I'm trying to write a custom Panel
I might be missing something here but am unable to understand the true purpose
I might be missing something obvious here, but I'm implementing NSCopying on one of
I might be missing something basic here, but I'm stumped on this error: model
I am new to JavaScript so I might be missing something obvious here, but
I might be missing something obvious here, but when trying to expose a Q_ENUM
I might be missing something obvious but is there a reference somewhere about what
I might be missing something about the intended behavior of list extend, but why
I am new to the C# XmlSerializer so I might be missing something basic

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.