Foros del Web » Programando para Internet » PHP »

Suma Ayuda

Estas en el tema de Suma Ayuda en el foro de PHP en Foros del Web. PORFA MUCHACHOS AYUDENEME CON ESTE CODIGO PARA SUMAR DOS CAMPOS <html> <head> <title>Web Modular</title> </head> <body> <form action="h.php"> <table> <TR><TD> <INPUT type="text" name="1"> <INPUT type="text" ...
  #1 (permalink)  
Antiguo 31/07/2007, 08:26
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
De acuerdo Suma Ayuda

PORFA MUCHACHOS AYUDENEME CON ESTE CODIGO PARA SUMAR DOS CAMPOS

<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$1=0;
$2=0;
$suma=val($1)+val($2);
print $suma
?>
  #2 (permalink)  
Antiguo 31/07/2007, 08:31
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Suma Ayuda

Código PHP:
<?php
$1=(int)$_POST['1'];
$
2=(int)$_POST['2'];
$suma=$+ $2;
print 
$suma;
?>
Saludos.
  #3 (permalink)  
Antiguo 31/07/2007, 08:31
 
Fecha de Ingreso: julio-2007
Mensajes: 71
Antigüedad: 16 años, 9 meses
Puntos: 1
Re: Suma Ayuda

Código PHP:
<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php">
<table> <TR><TD>
<INPUT type="text" name="a">
<INPUT type="text" name="b">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$suma
=$_POST['a']+$_POST['b'];
print 
$suma;
?>
Nunca pongas el nombre a la variable que empiece con numero (a lo sumo, podes empezar guión y despues numero, por ejemplo: _4)

Espero que hayas aprendido algo...
  #4 (permalink)  
Antiguo 31/07/2007, 08:33
 
Fecha de Ingreso: febrero-2005
Mensajes: 81
Antigüedad: 19 años, 2 meses
Puntos: 0
Re: Suma Ayuda

<form action='h.php' method='post'>

si es asi, primero tendrias que recibir las variables del estilo:

$dades=$_POST;

$suma=$dades['1']+$dades['2'];

echo $suma;

espero que esto te sirva
  #5 (permalink)  
Antiguo 31/07/2007, 08:39
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Suma Ayuda

no me funcionan ninguno de los dos muchachos
  #6 (permalink)  
Antiguo 31/07/2007, 08:42
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Suma Ayuda

ni asi da el resultado pruebenlo para q vean da es CERO


<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$dades=$_POST;

$suma=$dades['1']+$dades['2'];

echo $suma;
?>
  #7 (permalink)  
Antiguo 31/07/2007, 09:01
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
De acuerdo Ayuda Con Codigo De Suma

TENGO ESTE CODIGO QUIERO HACER UNA SUMA PERO ME DA ES CERO


codigo php:

<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$dades=$_POST;

$suma=$dades['1']+$dades['2'];

echo $suma;
?>
  #8 (permalink)  
Antiguo 31/07/2007, 09:07
Avatar de TolerantX  
Fecha de Ingreso: marzo-2006
Ubicación: Guadalajara, México.
Mensajes: 408
Antigüedad: 18 años, 1 mes
Puntos: 10
Re: Ayuda Con Codigo De Suma

Agregale que método quieres usar, GET o POST.

Código:
<form action="h.php" method="post" >
Y supongo que esta parte es el archivo h.php

Código PHP:
<?
$dades
=$_POST;

$suma=$dades['1']+$dades['2'];

echo 
$suma;
?>
__________________
TolerantX
http://tolerantx.com
Linux User #385226
  #9 (permalink)  
Antiguo 31/07/2007, 09:07
Avatar de mauled  
Fecha de Ingreso: marzo-2005
Ubicación: Cd. de México.
Mensajes: 3.001
Antigüedad: 19 años, 1 mes
Puntos: 33
Re: Ayuda Con Codigo De Suma

Modifica la siguiente linea

Código HTML:
<form action="h.php"> 
por

Código HTML:
<form action="h.php" method="post"> 
Saludillos
  #10 (permalink)  
Antiguo 31/07/2007, 09:09
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Ayuda Con Codigo De Suma

gracias pana se me habia pasado
  #11 (permalink)  
Antiguo 31/07/2007, 09:12
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Ayuda Con Codigo De Suma

pana y para hacer q el resultado se me vea en otro inpu text
  #12 (permalink)  
Antiguo 31/07/2007, 09:15
Avatar de TolerantX  
Fecha de Ingreso: marzo-2006
Ubicación: Guadalajara, México.
Mensajes: 408
Antigüedad: 18 años, 1 mes
Puntos: 10
Re: Ayuda Con Codigo De Suma

Por cierto, ¿Qué es pana?

Código PHP:
<input type="text" name="nombre" value="<?php echo $tu_variable?>" />
__________________
TolerantX
http://tolerantx.com
Linux User #385226
  #13 (permalink)  
Antiguo 31/07/2007, 09:18
 
Fecha de Ingreso: julio-2007
Mensajes: 71
Antigüedad: 16 años, 9 meses
Puntos: 1
Re: Suma Ayuda

Código PHP:

<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php" method='post'>
<table> <TR><TD>
<INPUT type="text" name="a">
<INPUT type="text" name="b">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?


$suma
=$_POST['a']+$_POST['b'];
echo 
$suma;

?>
Ya hice la prueba con el codigo que te lo modifique, y me anduvo...
fijate ahora si te funcionó!
  #14 (permalink)  
Antiguo 31/07/2007, 09:20
Avatar de the_scorpion  
Fecha de Ingreso: mayo-2006
Ubicación: Cuba
Mensajes: 696
Antigüedad: 17 años, 11 meses
Puntos: 3
Re: Suma Ayuda

Cita:
Iniciado por huascar Ver Mensaje
ni asi da el resultado pruebenlo para q vean da es CERO


<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$dades=$_POST;

$suma=$dades['1']+$dades['2'];

echo $suma;
?>
si da lo que un pequeño detalle a simple vista es que en el formulario no tienes el metodo de envio post o get
METHOD="POST"
<form action="h.php" METHOD="POST">
__________________
Que hablen mal de uno es espantoso. Pero hay algo peor: que no hablen.
Quien hace, puede equivocarse. Quien nada hace, ya está equivocado".
  #15 (permalink)  
Antiguo 31/07/2007, 09:23
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Ayuda Con Codigo De Suma

COMO HAGO PARA Q ESTE CODIGO ME MUESTRE EL RESULTADO EN UN INPUT TEXT POR LO MENOS EN RESULTADO

<html>
<head>
<title>Web Modular</title>

</head>

<body>
<form action="h.php"b method="POST">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
<?
$dades=$_POST;
$suma=$dades['1']+$dades['2'];
echo $suma
?>
  #16 (permalink)  
Antiguo 31/07/2007, 09:25
Avatar de the_scorpion  
Fecha de Ingreso: mayo-2006
Ubicación: Cuba
Mensajes: 696
Antigüedad: 17 años, 11 meses
Puntos: 3
Re: Ayuda Con Codigo De Suma

De seguro a de ser colega (creo que es versión argentina)
pero tambien porque repites tema si dejaste uno por aqui con la misma problemática
Otros tema
__________________
Que hablen mal de uno es espantoso. Pero hay algo peor: que no hablen.
Quien hace, puede equivocarse. Quien nada hace, ya está equivocado".
  #17 (permalink)  
Antiguo 31/07/2007, 09:44
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Ayuda Con Codigo De Suma

lo hice pana es para q me respondieran rapido porq tenia una idea pero no me daba bien el resultado y de pana que necesitaba el el codigo porq estoy atrazado con el sistema
  #18 (permalink)  
Antiguo 31/07/2007, 10:14
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
De acuerdo Ayuda Muchachos

COMO HAGO YO PARA SUMAR NUMEROS Y QUE LOS CAMPOS NO ME QUEDEN EN BLANCO CUANDO SE HAGA LA SUMA QUE SE SUME Y DE EL RESULTADO PERO LOS NUMEROS INTRODUCIDOS PARA REALIZAR LA SUMA SIGAN VISIBLES PORQ DESPUES LOS NECESITOS PARA GUARDARLOS Y SI LOS CAMPOS ESTAN VACIOS NO ME VA A GUARDAR SI NO EN DONDE DIO EL TOTAL ESTE ES EL CODIGO


<html>
<head>
<title>Web Modular</title>

</head>

<body>
<?
$d=$_POST;
$suma=$d['1']+$d['2'];
?>
<form action="h.php"b method="POST">
<table> <TR><TD>
<INPUT type="text" name="1">
<INPUT type="text" name="2">
<INPUT type="text" name="suma" value="<? echo $suma ?>">
<INPUT type="submit" name="suma" value="suma">
</TD></form>
</TR></table>
</body>
</html>
  #19 (permalink)  
Antiguo 31/07/2007, 10:22
Avatar de eskorbutin  
Fecha de Ingreso: junio-2006
Mensajes: 65
Antigüedad: 17 años, 10 meses
Puntos: 2
Re: Ayuda Muchachos

Debes hacerlo así como lo haces con el campo suma.


Código HTML:
.....

<form action="h.php"b method="POST"> <!--Quitale la letra b que esta después del cierre de comillas "h.php"b -->
<table> <TR><TD>
<INPUT type="text" name="1" value="<? echo $d['1'] ?>">
<INPUT type="text" name="2" value="<? echo $d['2'] ?>">
<INPUT type="text" name="suma" value="<? echo $suma ?>"> <!-- Dale nombres diferentes al botón y el text, por que los estas llamando igual "suma" -->
<INPUT type="submit" name="suma" value="suma">

...
  #20 (permalink)  
Antiguo 31/07/2007, 10:26
Avatar de cala932  
Fecha de Ingreso: septiembre-2006
Ubicación: San Juan-Argentina
Mensajes: 902
Antigüedad: 17 años, 7 meses
Puntos: 9
Re: Ayuda Muchachos

Hola, quizas no te he entendido bien, pero las variables $d['1'] y $d['2'] siguen manteniendo los valores que traian, aun despues de realizar la suma, si lo que quieres es mostrarlos colocalas en los input como hiciste con la suma. Otra cosa, creo que no se puede poner como nombre de variable un numero.
Saludos
__________________
->Aprender es un proceso que incluye el error..
  #21 (permalink)  
Antiguo 31/07/2007, 10:31
 
Fecha de Ingreso: julio-2007
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Re: Ayuda Muchachos

gracias amigos de verda muchas gracias
  #22 (permalink)  
Antiguo 31/07/2007, 11:59
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Re: Ayuda Con Codigo De Suma

Porfavor no dupliques temas.

Saludos.
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 07:45.