Page 1 of 1

require problems

Posted: Mon Mar 29, 2010 7:33 am
by abolzouz
hi everyone....

im having a weird problem using require....
i have two functions which query a database and then construct an object from the response of the database.
the weird thing is that one function works without the require of the class and the other doe not work even if i add the require.

this is my code

Code: Select all

<?php
require 'config.inc.php';

function login($id, $password) {
    $con = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_username'], $GLOBALS['db_password']) or die("could not connect to database");
    if($con) {
        $db = mysql_select_db($GLOBALS['db_name'], $con) or die("database problems");
        if($db) {
            $id = mysql_real_escape_string($id, $con);
            $password = mysql_real_escape_string($password, $con);

            /**
             * note that passwords are encrypted in MD5 hashes
             */
            $query = 'SELECT * FROM user WHERE id = "' . $id . '" AND password = "' . md5($password) . '" LIMIT 1';
            $resource = mysql_query($query, $con);
            if($resource) {
                $count = mysql_num_rows($resource);
                if($count == 1) {
                    
                    $row = mysql_fetch_assoc($resource);

                    $user = new User($row['id'],
                            $row['fname'],
                            $row['mname'],
                            $row['lname'],
                            $row['dob'],
                            $row['gender'],
                            $row['spouce'],
                            $row['numOfChildern'],
                            $row['employmentDate'],
                            $row['position'],
                            $row['department'],
                            $row['terminationDate'],
                            $row['address'],
                            $row['email'],
                            $row['privileges'],
                            $row['password'],
                            $row['mobileNumber']);

                    return $user;
                }else {
                    mysql_close($con);
                    return false;
                }
            }
        }
        mysql_close($con);
    }
}

function getCompanyMessage() {
    $companyMessages = array();

    $con = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_username'], $GLOBALS['db_password']) or die("could not connect to database");
    if($con) {
        $db = mysql_select_db($GLOBALS['db_name'], $con) or die("database problems");
        if($db) {
            $query = "SELECT title, message FROM company_message";
            $resource = mysql_query($query, $con);
            if($resource) {
                while($row = mysql_fetch_assoc($resource)) {
                    $cm = new CompanyMessage($row['title'], $row['message']);
                    $companyMessages[] = $cm;
                }
                return $companyMessages;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }
}
?>
as you can see that the second function query the DB and then construct successfully a CompanyMessage Object even though i did not include a "require" statement anywhere in this file;
while on the other hand the first function also query the DB and tries to create a user object but it fails....even if i add the require it also fails

thanks in advance

Re: require problems

Posted: Mon Mar 29, 2010 11:03 am
by omniuni
Hi,

What is the error you are given when it fails?

Re: require problems

Posted: Tue Mar 30, 2010 1:07 am
by abolzouz
never mind about it anymore....got it fixed....
the problem was that i had a typo that neither my IDE nor the PHP compiler complained about....
i say the typo by mistake, it would have taken me ages to debug this....

by the way i saw your business website,,,,im kinda building a very basic small scale CMS for very particular uses...any advices ?

thanks a lot again for your time

Re: require problems

Posted: Tue Mar 30, 2010 2:00 am
by omniuni
Hey, sure.

If you're building your own CMS, there are a few things that are good to keep in mind. One is spend a good amount of time thinking about the directory structure. Where are you going to put files that do different things? For example, I have a folder that contains the scripts for the CMS, and another folder to contain the resources editable by the CMS (images, photo galleries, files, etc.). Knowing how you're going to handle information will make updates easier in the future. I also recommend you figure out a good way to make it "plugin" based. Even if they're not true plugins, you should have an easy way to add functionality that doesn't require you to get completely involved in the rest of the CMS code.

What sort of things would you use your CMS for? If you give me more information, I might have some more suggestions.

Re: require problems

Posted: Tue Mar 30, 2010 2:09 am
by abolzouz
well it is a simple CMS that will manages news feeds....nothing fancy...maybe some pictures but nothing more....
how do u maintain the styling and formatting of text after you put it in a database? do u also store the html tags or it doesnt work this way ?

Re: require problems

Posted: Tue Mar 30, 2010 2:21 am
by omniuni
I use a combination of things. For one, the most simple page manager I have simply writes to files. Generally, I do store the HTMl tags, but I use a somewhat customized version of TinyMCE to restrict the options readily available to CMS users.

Re: require problems

Posted: Tue Mar 30, 2010 2:45 am
by abolzouz
thanks a lot for your time and for your help