Reputation: 1
Is it possible to store error messages(Fields are empty or incorrect credentials) in a variable and just echo it in a <div>
tag?
Upvotes: 0
Views: 269
Reputation: 31749
Try this -
$message = "Hello";
And
<?php if (!empty( $message)) {?>
<div><?php echo $message;?></div>
<?php }?>
if you are setting the messages on other pages then use session
. Like -
$_SESSION['message'] = "Hello";
And
<?php if (!empty( $_SESSION['message'])) {?>
<div><?php echo $_SESSION['message'];?></div>
<?php }?>
And dont forget to add session_start()
at the start of the page.
Upvotes: 4