I am trying to insert messages to a function
function addMessage($item) {
if ($result) {
$message = '<p class="ok">
<span> Item added </span>
</p>
';
header("Refresh: 2; url=?page=$item");
}
else{
$message = '<p class=not><span>There is an error blah blah</span></p>';
}
return $message;
}
When I use it : addMessage(‘contents’) it only returns to second condition. How can I fix this?
Hi jasmine
Your function always returns the second condition because you haven’t assigned a value to
$result, eider inside the function or when you call the function (like unicornaddict mentioned by other words).To get your code working the way you probably want, your function should be like this:
And then you can call the function like you where already calling it, but don’t forget to include a variable or a value that should be handled as the
$resultvariable inside the functionNote:
In your
$messagevariable you have<p class=not>and should be<p class="not">.Remember that
header()must be called before any actual output is sent to the browser.Hope it Helps.