Log in

View Full Version : On click display



keyboard
06-25-2011, 05:07 AM
Hi everyone. Here is a pretty basic php script.

<html><body>

<form action="order.php" method="post">

Name<input name="name" type="text" />
<input type="submit" />
</form>
</body></html>

<?php
$cheese = $_POST['name'];

echo "Welcome ". $cheese . ", to my webpage <br />";


?>

It does what I want, but is there a way to display the Welcome "name" to my webpage only after the button is clicked.


Thanks for any help

bluewalrus
06-25-2011, 05:38 AM
Not entirely sure I understand your question but does this work?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>My Page</title>
<body>
<?php
if (!empty($_POST['name'])) {
$cheese = $_POST['name'];
echo "Welcome ". $cheese . ", to my webpage <br />";
} else {
?>
<form action="order.php" method="post">
Name:<input name="name" type="text" />
<input type="submit" />
</form>
<?php
}
?>
</body>
</html>

keyboard
06-25-2011, 06:40 AM
Perfect. Thankyou very much.