Reputation: 204
I don't understand this at all.
I have a class which is roughly 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 eventually end up with:
mysql_query("INSERT INTO Records (Bookmark, Program, Agency)
VALUES ('$data->getBookmark()', '$data->getProgram()', '$data->getAgency()')");
I end up with Notice: Undefined property: pageData::$getBookmark in...
Notice: Undefined property: pageData::$getProgram in...
Notice: Undefined property: pageData::$getAgency in...
Using PhpMyAdmin it looks like Bookmark becomes 0 and Program becomes () and Agency is empty.
If I type
print($data->getBookmark());
it prints out the bookmark. if I type
echo $data->getBookmark();
it prints out. Why doesn't it work when I try to insert it into the database, too?
Upvotes: 3
Views: 2644
Reputation: 6660
When using anything other than a normal variable in a string you should add curly brackets around the values:
mysql_query("INSERT INTO Records (Bookmark, Program, Agency)
VALUES ('{$data->getBookmark()}', '{$data->getProgram()}', '{$data->getAgency()}')");
Upvotes: 1
Reputation: 46728
It is getting interpreted as a data-member
The variable $data->getBookmark
followed by ()
Do
mysql_query("INSERT INTO Records (Bookmark, Program, Agency)
VALUES ('".$data->getBookmark()."',...
Upvotes: 1