Page 1 of 1

A little advice needed

Posted: Thu Apr 17, 2008 10:48 am
by ianhull
Hi all,

Just wondering if anyone could give me a little advice on classes and if there could possibly be any issues with the folowing code

Thanks in advance :)

Code: Select all

 
 
class companyManager {
 
//////////ADD COMPANY
function addCompany($postedParameters){
 
if(isset($postedParameters['companyLogo'])){
 
$target_path = '_company_logos/'.basename(strtolower($postedParameters['companyLogo']));
move_uploaded_file($postedParameters['companyLogo'], $target_path)
 
 
};//end if
 
foreach($postedParameters as $key => $value){
 
$tableColumns .= ''.$key.', ';
$tableValues .= ''.$value.', ';
 
};//end foreach
 
$tableColumns = strlen($tableColumns)-2};
$tableValues = strlen($tableValues)-2};
 
connectMySQL();
 
mysql_query("INSERT INTO companies ('$tableColumns') VALUES ('$tableValues')")or die(mysql_error());
 
echo '<meta http-equiv="refresh" content="0;URL=../" />';
 
};//end function
 
 
//////////UPDATE COMPANY
 
function updateCompany($postedParameters){
 
if(isset($postedParameters['companyLogo'])){
 
$target_path = '_company_logos/'.basename(strtolower($postedParameters['companyLogo']));
move_uploaded_file($postedParameters['companyLogo'], $target_path)
 
};//end if
 
foreach($postedParameters as $key => $value){
 
$queryString .= '''.$key.'' = ''.$value.'' ';
 
};//end foreach
 
connectMySQL();
 
mysql_query("UPDATE companies SET $queryString")or die(mysql_error());
 
echo '<meta http-equiv="refresh" content="0;URL=../" />';
 
};//end function
 
};//end class companyManager 
 

Re: A little advice needed

Posted: Thu Apr 17, 2008 12:45 pm
by Christopher
I guess it looks fine as a gateway class. I don't like the mixing of uploading files and saving database records, but it might make sense in the way you are using your class. You could also probably combine the add and update methods into one save method because they are similar except for the SQL. That might simplify using the class.