Thanks for helping me guys. I have another question.
In my previous question I asked how to make the textbox message to show at the top of page after form submission.
I managed to do this thanks to you guys.
Next question is how to make this happen at least 8x times?
<?php
include('header1.php');
if(isset($_POST['submit']) && $_POST['submit']=='Submit'){
message=$_POST['message'];
$name=$_POST["name"];
echo "<center>";
echo "<div>" . $name . "<br />" . $message ."</div>";
echo "</center>";
if(isset($_POST['submit']) && isset($_POST['prevmsg']) && isset($_POST['prevname'])){
echo "<center>";
echo $_POST['prevname'];
echo "<br/>";
echo $_POST['prevmsg'];
echo "</center>";
}
?>
<html>
<head>
</head>
<body style="position:center">
<form method="POST" action="<?=$_SERVER["PHP_SELF"]?>">
<table>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<input type="hidden" name="prevname" value="<?=$name?>"/>
<tr>
<th>
<label for="message">Message</label>
</th>
<td>
<textarea name="message" id="message"></textarea>
</td>
</tr>
<input type="hidden" name="prevmsg" value="<?=$message?>"/>
</table>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php
} else {
?>
<html>
<head>
</head>
<body>
<form method="POST" action="<?=$_SERVER["PHP_SELF"]?>">
<table>
<tr>
<th>
<label for="name">Name</label>
</th>
<td>
<input type="text" name="name" id="name">
</td>
</tr>
<tr>
<th>
<label for="message">Message</label>
</th>
<td>
<textarea name="message" id="message"></textarea>
</td>
</tr>
</table>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
<?php }
include('inc/footer.php');
?>
You can use a
forloop. I also cleaned up your code as you had some syntax errors. Since you’re reusing the form, you probably want to make it a function.