Reputation: 61
I am trying to display results of a mysql query and some html if the first mysql queries coulmn returns false or is set to false. I've tried a few things but I can't seem to get it to work properly, I will show code below. Any help is much appreciated. In the code I want to only display site message if the user's acknowledgement is false otherwise don't display anything.
function siteWideMessage()
{
global $dbh;
$siteMessage = "";
$sUserInfo = $dbh->prepare("
SELECT acknowledgement
FROM user
WHERE uid = :uid
");
$sUserInfo->bindValue(":uid", $_SESSION["uid"]);
if ($sUserInfo->execute()) {
$res = $sUserInfo->fetch();
if ($res["acknowledgement"] = false) {
$stmt = $dbh->query("
SELECT message
FROM SiteWideMessages
ORDER BY idSiteWideMessages DESC
LIMIT 1
");
while ($row = $stmt->fetch()) {
$siteMessage .= "
<div class='siteMessage'>
<span>" . $row["message"] . "</span>
<br><br>
<span style='font-weight:normal;'>I acknowledge that I have read this important site message</span>
<br>
<input type='submit' name='submit' value='I Agree'></input>
</div>";
}
}
$sUserInfo->closeCursor();
}
if (isset($_POST["submit"])) {
$stmt = $dbh->prepare("
UPDATE user
SET `acknowledgement` = 'true'
WHERE uid = :uid
");
$stmt->bindValue(":uid", $_SESSION["uid"]);
if($stmt->execute()) {
$stmt->closeCursor();
}
}
return $siteMessage; }
UPDATE: I managed to get it working the way I want it to I just had to do as the following.
if ($res["acknowledgement"] == 'false')
Thanks for everyone's help!
Upvotes: 1
Views: 42
Reputation: 33186
You are missing an =
in your if statement. It should be:
...
if ($res["acknowledgement"] === false) {
...
Upvotes: 1