elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: AIO elhacker.NET 2021 Compilación herramientas análisis y desinfección malware


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Calculadora en Html y Php
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Calculadora en Html y Php  (Leído 37,897 veces)
eat7herich

Desconectado Desconectado

Mensajes: 59


Insomnio... Insomnio... Insomnio... arghhh....


Ver Perfil
Calculadora en Html y Php
« en: 25 Octubre 2007, 19:54 pm »

aca les dejo el código de mi primer php.
ya voy a subir algunas otras cosas que hice mas complejas.
el problema es que tengo todo sin terminar ajaj.
pero para principiantes este código va como piña que lo disfruten.

calculadora.htm
Código:
<html>
<head>
<title>Calculadora básica en html y php por eat7herich</title>
</head>
<body>
<Font color=red>Ingresa las 2 cifras a calcular:</Font><br>
<form action="calculadora.php" method=post>
<input type="text" name="cifra1" size="10" maxlength="10"><br>
<input type="text" name="cifra2" size="10" maxlength="10"><br>
<input type=submit name="sumar" value="Sumar">
<input type=submit name="restar"value="Restar">
<input type=submit name="dividir" value="Dividir">
<input type=submit name="multiplicar" value="Multiplicar">
</form>
</body>
</html>

calculadora.php
Código:
<html>
<head>
<title>Calculadora básica en html y php por eat7herich</title>
</head>
<body>
<?
if($cifra1==0)
{
echo "ERROR 01: No ingreso la primer cifra.<br>";
}
if($cifra2==0)
{
echo "ERROR 02: No ingreso la segunda cifra.";
}
else
{
echo "Resultado de la operación:<br>";
$resultadodivision=$cifra1/$cifra2;
$resultadomultiplicacion=$cifra1*$cifra2;
$resultadoresta=$cifra1-$cifra2;
$resultadosuma=$cifra1+$cifra2;
if($sumar)
echo $resultadosuma;
if($restar)
echo $resultadoresta;
if($multiplicar)
echo $resultadomultiplicacion;
if($dividir)
echo $resultadodivision;
}
?>
<br><br><A HREF=calculadora.htm>Realizar una nueva operación.</A>
</body>
</html>

cya
eat7herich


« Última modificación: 28 Septiembre 2011, 07:21 am por eat7herich » En línea

chilling

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Re: Calculadora en Html y Php
« Respuesta #1 en: 17 Febrero 2013, 02:50 am »



BUENAS TARDES  MIRA TENGO EL SIGUIENTE CODIGO CREADO PARA LA CALCULADORA Y ME PERMITE INGRESAR LOS NUMEROS PERO NO ME MUESTRA EL RESULTADO ME PODRIAS AYUDAR GRACIAS
<html>
<head>
<title>calculadora</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="218" border="1">
    <tr>
      <th width="97" scope="row">numero_1</th>
      <td width="105"><p>
        <label for="num_1"></label>
        <input type="text" name="num_1" id="num_1" />
      </p></td>
    </tr>
    <tr>
      <th scope="row">numero_2</th>
      <td><label for="num_2"></label>
      <input type="text" name="num_2" id="num_2" /></td>
    </tr>
    <tr>
      <th scope="row"><input name="sumar" type="submit" id="sumar" value="+" />
      <input name="-" type="submit" id="cmdResta" value="-" /></th>
      <td><input name="/" type="submit" id="cmdDivide" value="/" />
      <input name="*" type="submit" id="cmdMultiplica" value="*" /></td>
    </tr>
  </table>
  <?
$cmdSuma=$_post["cmdSuma"];
$cmdResta=$_post["cmdResta"];
$cmdmult=$_post["cmdmult"];
$cmddivde=$_post["cmdDivide"];
$num_1=$_post["num_1"];
$num_2=$_post["num_2"];

$sumar = $num_1+$num_2;

 if ($cmdSuma){
 echo "la suma es:";$Sumar;
 }
 
 
?>

</form>
</body>
</html>


En línea

Ori-chan

Desconectado Desconectado

Mensajes: 257


El rey de los novatos en persona.


Ver Perfil
Re: Calculadora en Html y Php
« Respuesta #2 en: 17 Febrero 2013, 17:14 pm »

Esta muy bien. Pero no consumiria menos memoria hacer esto: (ste ejemplo es en el caso de sumar):

Código
  1. if($sumar)
  2. $resultadosuma=$cifra1+$cifra2;
  3. echo $resultadosuma;

Y asi con todas. No?




Un saludo!!
« Última modificación: 27 Febrero 2013, 17:00 pm por Ori-chan » En línea


Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines