I have extracted these codes from a complete script of mine, the string $stat will only be "Printed" after the $stat is set and the page is refreshed .. How can we recode the script so that the $stat gets displayed without a need to refresh the page. <?php $stat=$_SESSION['stat']; if ( ( $_POST["code"] == $rand ) && ( $_POST["message"] != "" ) ) { $_SESSION['stat'] ="Message Submitted"; } elseif (( $_POST["message"] == "" ) && ( $stat != "" )) { $_SESSION['stat'] ="No message entered"; } elseif (( $_POST["code"] != $rand ) && ( $stat != "" )) { $_SESSION['stat'] ="Wrong verification code"; } echo $stat; ?> Code (markup): Again, a summary of the problem: 1)Script sets a value for $stat after checking through an IF condition. 2)$stat does not gets displayed because the string for $stat was set AFTER the page is loaded. 3)$stat gets displayed after a page refresh because at that point $stat is set ( previous $stat value, not the new one )
First thing - check if your $rand works .. Second thing - you don't need to reload the page - PHP works as 1,2,3 .. 1 will add a value, 2 will print it out
It works, I have removed the other statements which were present within the IF condition box but they do get executed along with the setting up for the $stat string. $stat string does still not gets displayed however.