Foros del Web » Programando para Internet » PHP »

suma

Estas en el tema de suma en el foro de PHP en Foros del Web. <?php if ($btnsumar) { if (!$txtuno) { echo "Debe ingresar valores para el primer numero. Vuelva atras con su browser e ingrese los datos.\n"; exit; ...
  #1 (permalink)  
Antiguo 12/12/2004, 22:06
 
Fecha de Ingreso: noviembre-2004
Mensajes: 181
Antigüedad: 19 años, 5 meses
Puntos: 1
Pregunta suma

<?php

if ($btnsumar)
{
if (!$txtuno)
{
echo "Debe ingresar valores para el primer numero. Vuelva atras con su browser e ingrese los datos.\n";
exit;
}

if (!txtdos)
{
echo "Debe ingresar el segundo numero. Vuelva atras con su browser e ingrese los datos.\n";
exit;
}

tres=$txtuno+$txtdos
$txttres=tres
echo"$txttres";

}
else //if($btnbuscar)
{
echo "<body>\n";
echo"<form action='$PHP_SELF' method='post' name='form1'>\n";
echo"<center>\n";
echo"<table border='1' width='100'>\n";

echo"<tr>\n";
echo"<td width='33%'><font face='Verdana'><b>primer umero</b></font></td>\n";
echo"<td width='33%' align='center'><font face='Verdana'><b>:</b></font></td>\n";
echo"<td width='34%' align='center'> <div align='left'>\n";
echo"<input name='txtuno' type='text' value='$txtuno' size='15' maxlength='10'>\n";
echo"</div></td>\n";
echo"</tr>\n";

echo"<tr>\n";
echo"<td width='33%'><font face='Verdana'><b>segundo numero</b></font></td>\n";
echo"<td width='33%' align='center'><font face='Verdana'><b>:</b></font></td>\n";
echo"<td width='34%' align='center'> <div align='left'>\n";
echo"<input name='txtdos' type='text' value='$txtdos' size='15' maxlength='10'>\n";
echo"</div></td>\n";
echo"</tr>\n";

echo"<tr>\n";
echo"<td width='33%'><font face='Verdana'><b>resultado</b></font></td>\n";
echo"<td width='33%' align='center'><font face='Verdana'><b>:</b></font></td>\n";
echo"<td width='34%' align='center'> <div align='left'>\n";
echo"<input name='txttres' type='text' value='$txttres' size='15' maxlength='10'>\n";
echo"</div></td>\n";
echo"</tr>\n";

echo"<input type='submit' name='btnsumar' value='sumar' >\n";
echo "</body>\n";
echo "</html>\n";
}
?>
LO QUE QUIERO ES Q SUME LOS DOS CUADROS DE TEXTO Y META EL RESULTADO EL EL TERSERO, PERO NO ME SALE PORFA UNA AYUDITA COMO SE HACE PLISS SI ESTA BIEN LO Q ETOY ASIENDO.GRACIAS
  #2 (permalink)  
Antiguo 13/12/2004, 02:09
Avatar de FuLaNo_  
Fecha de Ingreso: mayo-2003
Ubicación: Don Torcuato, Buenos Aires, Argentina
Mensajes: 1.250
Antigüedad: 20 años, 10 meses
Puntos: 2
Falta el $ a la variable tres y los ;

tres=$txtuno+$txtdos
$txttres=tres
echo"$txttres";

Tendria que ser:

$tres=$txtuno+$txtdos;
$txttres=$tres;
echo $txttres;
__________________
I Love Programming...

Última edición por FuLaNo_; 13/12/2004 a las 02:11
  #3 (permalink)  
Antiguo 13/12/2004, 02:16
Avatar de FuLaNo_  
Fecha de Ingreso: mayo-2003
Ubicación: Don Torcuato, Buenos Aires, Argentina
Mensajes: 1.250
Antigüedad: 20 años, 10 meses
Puntos: 2
Otra cosa, cuando pones:
echo"<input name='txttres' type='text' value='$txttres' size='15' maxlength='10'>\n";

Te combiene ponerlo así:
echo '<input name="txttres" type="text" value="'.$txttres.'" size="15" maxlength="10">';

Porque?, pues creo que PHP es quien se tiene que "adaptar" a html y no html a PHP, si en html no usas "" no importa, pero si mañana usas XHTML tendrás porblemas ya que los "" son obligatorios.
__________________
I Love Programming...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:11.