I'm new in PHP. I have simple script which displays my string variable ('Hello, World') when I press the button. But it doesn't work if I put the form into a loop. I guess value of hidden input didn't initialize by some reason. How can I fix it?
<body>
<?php
$testvariable = 'Hello, World!';
for ($i=0; $i < 3; $i++) {
echo '<form name="tesst" method="POST" action="test.php">
<input type="hidden" name="hidden_name" value="<?php echo $testvariable ?>">
<input type="submit" name="te1st" value="Buttonfor">
</form>';
}
?>
<form name="tesst" method="POST" action="test.php">
<input type="hidden" name="hidden_name" value="<?php echo $testvariable ?>">
<input type="submit" name="te1st" value="Button1">
</form>
<?php
if (isset($_POST) && isset($_POST['hidden_name']))
echo strval($_POST['hidden_name']);
?>
[Result][https://i.stack.imgur.com/mrs6R.png]