Jump to content
Fórum Script Brasil
  • 0

Dúvida de Retorno


RANIEL NOGUEIRA

Question

Pessoal, estou com uma dúvida gostaria de saber como faço para retornar o valor de um formulario na mesma página.

Meu PHP => func_calc.php

<?
function somar($num1,$num2,$num3,$num4){
$num1 = "$_POST[num1]";
$num2 = "$_POST[num2]";
$num3 = "$_POST[num3]";
$num4 = "$_POST[num4]";
$resultado = $num1+$num2+$num3+$num4;
return $resultado;
}
?>
HTML form_calc.php
<? require_once "func_calc.php" ?>
<form  method="POST">

<input type="text" name="num1"/>
<input type="text" name="num2"/>
<input type="text" name="num3"/>
<input type="text" name="num4"/>
<input type="submit" value="soma"/>

</form>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

você precisa dar echo no resultado retornando no caso na chamada da function e você nem chama ela ai...

você fez praticamente 90% errado se for para mecher com função...

tenta assim e ve se da certo.

<?php
function somar($num1,$num2,$num3,$num4){
$resultado = $num1+$num2+$num3+$num4;
return $resultado;
}
?>

<?php require_once "func_calc.php"

if($_POST {

echo somar($_POST[num1],$_POST[num2],$_POST[num3],$_POST[num4]);

})

 ?>
<form action="" method="POST">

<input type="text" name="num1"/>
<input type="text" name="num2"/>
<input type="text" name="num3"/>
<input type="text" name="num4"/>
<input type="submit" value="soma"/>

</form>

Edited by JaguA
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...