En el archivo html
<html>
<head><title> MENUS </title>
<style type="text/css">
[required]{
border-color:red;
box-shadow:0px 0px 5px green;
}
</style>
</head>
<body>
<form action="menu.php" method="post" name="mod">
<center>
<table border=4>
<tr><td>cuantos numeros: </td>
<td><input type="text" name="num" required > </td>
</tr>
<tr>
<td><input type="submit" value = "ejecutar"> </td>
</tr>
</table>
</form>
</body>
</html>
<head><title> MENUS </title>
<style type="text/css">
[required]{
border-color:red;
box-shadow:0px 0px 5px green;
}
</style>
</head>
<body>
<form action="menu.php" method="post" name="mod">
<center>
<table border=4>
<tr><td>cuantos numeros: </td>
<td><input type="text" name="num" required > </td>
</tr>
<tr>
<td><input type="submit" value = "ejecutar"> </td>
</tr>
</table>
</form>
</body>
</html>
En el archivo php
<html>
<?php
$num=$_POST['num'];
echo "<FORM
ACTION='sum.php' method='POST'>";
for($i=1;$i<=$num;$i++)
{echo "<table
border=2>
<tr><td>VALOR$i</td>
<td><input type='interger'
name='VALOR[$i]'></TD></TR>
</table>";
}
echo "<br>";
echo "<input
type='submit' value='suma' name='enviar'>";
echo "<br>";
echo "<input
type='submit' value='resta' name='enviar'>";
echo "<br>";
echo "<input
type='submit' value='multiplicacion' name='enviar'>";
echo "<br>";
echo "<input
type='submit' value='divicion' name='enviar'>";
echo "</form>";
?>
</html>
<?php
$array = $_POST['VALOR'];
$sum=0;
$res=0;
$mul=1;
$divi=1;
switch($_POST["enviar"])
{
case 'suma':
for($i=1;$i<=count($array);$i++)
{$sum=$sum+$array[$i];
}
echo
"la suma de los valores es:"." ".$sum;
break;
case 'resta':
for($i=2;$i<=count($array);$i++)
{
$res=$res-$array[$i];
}
echo
"El resultado de la resta de los valores es:"." ".$res;
break;
case 'multiplicacion':
foreach ($array as $valores)
{
$mul=$mul*$valores;
}
echo
"El resultado de la multiplicacion de los valores es:"." ".$mul;
break;
case 'divicion':
foreach ($array as $valores)
{
$divi=$valores/$divi;
}
echo
"El resultado de la divicion de los valores es:"." ".$divi;
break;
}
?>
No hay comentarios:
Publicar un comentario