I have the following code:
$var1 = 'Hello';
$var2 = $var1.' friend';
Inside the if statement, if submit is clicked, I want to update var1 to 'Hi' so I am expecting 'Hi friend' as output. But it was not working- 'Hello friend' is still the output. I want to call it via var2. How can var1 be updated which is in var2?
Here is my full code:
<?php
$var1 = 'Hello';
$var2 = $var1.' friend';
if(isset($_POST['submit'])) {
$var1 = 'Hi';
echo $var2;
} else{
echo '<form method="post" action="'. $_SERVER['PHP_SELF'] .'">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br> </form>';
}
?>