Two methods to run PHP script
Information Technology December 8th, 2009HTML with PHP :-
HTML: add.htm
<html>
<head>
<title>Adding two numbers</title>
</head>
<body>
<form action=”add.php” method=”post”>
Enter the first number: <input type=”text” name=”a” size=10><br>
Enter the second number: <input type=”text” name=”b” size=10><br>
<input type=”submit” name=”submit” value=”ADD”>
</form>
</body>
</html>
PHP: add.php
<html>
<head>
<title>Adding two numbers</title>
</head>
<body>
<?php
$a=$_POST["a"];
$b=$_POST["b"];
$c=$a+$b;
print “Addition of $a and $b is $c.”;
?>
</body>
</html>
Only with PHP :-
<?php
$a = $_POST["a"];
$b = $_POST["b"];
if (!isset($_POST['add']))
{ // If page is not submitted to itself echo the form
?>
<html>
<head>
<title>Adding Two Numbers</title>
</head>
<body>
<form method=”post” action=”<?php echo $PHP_SELF; ?>”>
Enter the first number: <input type=”text” size=”12″ maxlength=”12″ name=”a”></br>
Enter the second number: <input type=”text” size=”12″ maxlength=”36″ name=”b”></br>
<input type=”submit” value=”ADD” name=”add”>
</form>
<?
}
else
{
$c=$a+$b;
print “Addition of $a and $b is $c.”;
}
?>
</body>
</html>
Recent Comments