Re: problem with my class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/4/16 Luke <luke@xxxxxxxxxxxxxx>:
> Hi guys,
>
> I've been learning about object oriented programming and I wrote this test
> class but it doesn't seem to be working, it throws no errors but doesn't
> insert anything to the database either. I have made sure that the data being
> sent when the class is instantiated is valid.
>
> I'm probably missing something simple here...
>

Are you actually calling your public function?

$x = new RecipeCreator('a', 'b', 'c');
$x->saveRecipe();

You might want to insert some error reporting...

echo mysql_error(); and alike


Byebye




> I have already
>
> class RecipeCreator
> {
>        private $rtitle;
>        private $problem;
>        private $solution;
>
>        function __construct ($t, $p, $s)
>        {
>                if(!isset($t, $p, $s))
>                {
>                        throw new Exception ('Missing parameters for
> __construct, need $title $problem and $solution');
>                }
>
>                $this->rtitle   = mysql_real_escape_string($t);
>                $this->problem  = mysql_real_escape_string($p);
>                $this->solution = mysql_real_escape_string($s);
>        }
>
>        public function saveRecipe()
>        {
>                $query = "INSERT INTO recipe (title, problem, solution)
> VALUES ('".$this->rtitle."',
>
>   '".$this->problem."',
>
>   '".$this->solution."')";
>                mysql_query($query);
>        }
> }
>
> Many thanks,
> Luke Slater
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux