Home >>PHP Tutorial >Multiple submit buttons php different actions

Multiple submit buttons php different actions

Handle Multiple submit buttons PHP different actions

<?php

extract($_POST);

//do addition and store the result in $res
if(isset($add))
{
$res=$fnum+$snum;
}	

//do subtraction and store the result in $res
if(isset($sub))
{
$res=$fnum-$snum;
}	

//do multiplicatio and store the result in $res
if(isset($mult))
{
$res=$fnum*$snum;
}	
 
?>
 
<html>

<head>

	<title>Display the result in 3rd text box</title
	>

	</head>

	<body>
	
<form method="post">

 <table align="center" border="1">
 
	<Tr>
	
	<th>Result</th>
	
	<td><input type="text" value="<?php echo @$res;?>"/></td>
	
	</tr>
	
	<tr>
	
		<th>Enter first number</th>
		
		<td><input type="text" name="fnum"/></td>
		
	</tr>	
	
	<tr>
	
		<th>Enter second number</th>
		
		<td><input type="text" name="snum"/></td>
		
	</tr>
	
	<tr>
	
		<td align="center" colspan="2">
		<input type="submit" value="+" name="add"/>
		<input type="submit" value="-" name="sub"/>
		<input type="submit" value="*" name="mult"/>
		
	</tr>
	
	</table>	
	
</form>

</body>

</html>

Total Downloads : 91

Login / Register To Download

No Sidebar ads