A little advice needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

A little advice needed

Post 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 
 
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: A little advice needed

Post 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.
(#10850)
Post Reply