Web Programming with PHP

17 Example of Getting Data from a Web Form

Check the living example.

comment.php

Make a comment web form

<!DOCTYPE html>
<!-- comment.php -->
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Make a comment</title>
</head>
<body>
<h1>Make a comment</h1>
<form action="save_comment.php" method="post">
<p>
Name:
<input type="text" name="name" />
<br />
Email:
<input type="email" name="email" />
<br />
Comment:
<textarea name="comment" rows="10" cols="60"></textarea>
<br />
<input type="submit" value="Send comment" />
</p>
</form>
</body>
</html>

Diagram of Make a comment web form

save_comment.php

Make a comment response

<!DOCTYPE html>
<!-- save_comment.php -->
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Make a comment</title>
</head>
<body>
<h1>Make a comment</h1>
<p>
Thank you for your participation!
We have registered your comment in our database:
</p>
<ul>
<li>Name:
<strong><?php echo $_POST['name']; ?></strong>
</li>
<li>Email:
<strong><?php echo $_POST['email']; ?></strong>
</li>
<li>Comment:
<strong><?php echo $_POST['comment']; ?></strong>
</li>
</ul>
</body>
</html>

Diagram of Make a comment response

Relation between comment.php and save_comment.php

Diagram of relation between comment.php and save_comment.php