I am trying to create an instance of a class "announcement".
For example:
$announcement = new announcement;
//code to bind data
$announcement->store();
My store function runs a query to store the information to the database. Everything is working as intended and storing to my database. However when I say:
if($announcement->store())
{
echo 'success';
}
else{
echo 'failure';
}
I get the 'failure' message. Why is my method returning false when it is actually working? Am I missing something with conditional statements and methods?
UPDATE My store function was not returning anything. So even though it worked it was returning a null value. I return true on query success and now it is working as intended. Thank you.
The store function should return true
then your statement will print success
message
class announcement {
public function store() {
// after execution code the return value should be like this
return true;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.