Here’s a simple PHP program I’ve made to make Hello World! a little more interactive.
Hello PHP Example
This program uses an HTML form to ask for the users name.
<form method="post" action="/scripts/helloworld.php">
<label for="firstname">What's your name?:</label>
<input type="text" id="firstname" name="firstname" /><br />
<input type="submit" value="Submit" name="submit" />
</form>
The PHP part of this program saves the data from the form to a variable and then says hello to whatever is inside the variable. Which could be the users name or whatever they decided to input into the form. I didn’t bother to validate anything.
<?php
$first_name = $_POST['firstname'];
if ($first_name) {
echo "<h2>Hello $first_name!</h2>";
}
if ($first_name) {
echo "<p class=\"textbox\">I know, there really isn't much wow factor to this either.<br />";
echo "But this at least shows PHP's dynamic capabilities.<br />";
echo "You can't replicate these results with just html by itself</p>";
}
?>