require problems
Posted: Mon Mar 29, 2010 7:33 am
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
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
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;
}
}
}
?>
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