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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:59:35+00:00 2026-05-27T03:59:35+00:00

Ok I am learning php and trying out classes and functions. Currently I have

  • 0

Ok I am learning php and trying out classes and functions. Currently I have multiple pages where it has the same menu bar and user info so I decided to create a class Common and a function menu to load user info and echo info and menu content. For some reason it is not displaying anything help?

class Content {
    public function menu($userid) {
        require_once("../class/class1.php");
        echo '<div id="logo"></div>
            <div style="clear:both;"></div>';
        echo '<div id="user">Welcome ';

        $db = new MySQL();
        $user = new User();
        $sql = $db->sql($user->loadUser($userid));

        if ($db->num_rows($sql) > 0) {
            while ($row = $db->fetch_array($sql)) {
                echo $row['name'] . ' ' . $row['lastname'];
            }
        }
    }
}

HTML:

require_once("content.php");
$content = new Content();
echo $content->menu($userid);

when running in localhost i get the following error:

Fatal error: Cannot redeclare class Sql in C:\xampp\htdocs\orbecargo\class\sql.php on line 3

that file is:

class MySQL
{
private $conexion;
private $total_consultas;

public function MySQL(){
    if(!isset($this->conexion)){
        $this->conexion = (mysql_connect("server","username","password")) or die(mysql_error());
        mysql_select_db("database",$this->conexion) or die(mysql_error());
        mysql_set_charset('utf8',$this->conexion);
    }
}
}

the weird thing is that other pages work perfectly…
and I removed the

echo $content->menu($userid);  

and still nothing

  • 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-27T03:59:35+00:00Added an answer on May 27, 2026 at 3:59 am
    echo $content->menu($userid);
    

    menu() does not return anything

    remove the echo before the menu(); to

    require_once("content.php");
    $content = new Content();
    $content->menu($userid);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I am trying to start really learning OOP style in PHP. I have
I have been trying to learn about classes in PHP and part of my
I'm just learning PHP and I'm trying to figure out how I could store
I am learning PHP and SQL, and I'm trying to figure out how to
I am learning php, trying to use the fopen() function. The php file I
I am crash-learning PHP for a project, and I have a ton of stupid
I'm learning PHP. The PHP has inline commands in HTML code to produce dynamic
I am working on a small project for learning PHP better. This project has
Bear with me, I have been only learning PHP for only a few weeks,
I am trying to cobble together a login script in PHP as a learning

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.