Insert data from class into database using PHP
I don't understand this at all.
I have a class that looks like the following:
<?php
class pageData
{
private $Bookmark;
private $Program;
private $Agency;
//With appropriate setters/getters
}
?>
Then I try to create a new object, pass it around a bit, and end up with:
mysql_query("INSERT INTO Records (Bookmark, Program, Agency)
VALUES ('$data->getBookmark()', '$data->getProgram()', '$data->getAgency()')");
Ultimately with Notice : Undefined property: pageData :: $ getBookmark in ...
Note : Undefined property: pageData :: $ getProgram in ...
Notice : Undefined property: pageData :: $ getAgency in ...
Using PhpMyAdmin looks like this: Bookmark becomes 0 and Program becomes () and Agency is empty.
If I type
print($data->getBookmark());
prints the bookmark. if i print
echo $data->getBookmark();
is printed out. Why doesn't it work when I try to insert it into the database too?
+3
source to share
2 answers