Page 1 of 1

trying to create a Class!

Posted: Mon Jul 26, 2010 9:56 am
by cap2cap10
Hello, again php Technorati. Ok, I am attempting to create my first class app that will send out an email when the user selects "Yes". The app will check if the user selected yes first, match the $category to the Mysql categories(cat_1 to cat_5) that are already in the database. If they match, email will be sent! :D Here is my flawed attempt at creating this class:

Code: Select all

class Send_port{
      public $activate_res = $_POST['activate_res'];
      public $category = $info['category'];
      public $portID = $info['portID'];
      public $indust = array ('cat_1' => $category,
                               'cat_2' => $category,
                               'cat_3' => $category,
                               'cat_4' => $category,
                               'cat_5' => $category );
      function ($activate_res){
      switch ($activate_res)
             case 'Yes';

                 $query = "SELECT * FROM mail WHERE '$indust' = '$category'";
                 $result = mysql_query($query) or die (mysql_error());

                 while($row = mysql_fetch_assoc($result))
                 {
                 $message = "Hello, ";
mail($row['email'], "Whats up!", $message, "From: Batoe" );
                 }
                 break;

              case 'No';

                 break;

}
}
1) cat_1 to cat_5 is already in the database with saved categories. I need make sure that if any one of them is equal to $category, then the email will be sent! I tried to use an associative array, but I am not sure if this is the correct way to perform this task. Nor am I sure if my method function is correct. Can someone enlighten me on the efficient way of creating a class that will perform this function!

Thanks in advance!

Batoe

Re: trying to create a Class!

Posted: Mon Jul 26, 2010 10:06 am
by VladSun
You can not put non constant initialization values for your class properties. You should use a constructor and pass these values at object creation (the new operator).
You should sanitize your user input by using the mysql_real_escape_string() function. Otherwise your application is vulnarable to SQL injection attack.

Also, a class should be a noun, not a verb ;)