Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Gardenajj

[Resolvido] Erro na hora de emprimir resultados

Recommended Posts

Galera a minha calculadora basica funciona de boa no Linux mais na hora que executo ela no windows não!

Estou utilizando o metodo GET e o erro da na linha 63 onde não consigo emprimir o resultado!

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Calculadora</title>

</head>

<?php

 

$valor1 = $_GET['valor1'];

$valor2 = $_GET['valor2'];

$opcao = $_GET['opcao'];

$total = $_GET['total'];

 

if ($opcao == somar){

 

$total = ($valor1 + $valor2);

echo "$total";

}

elseif ($opcao == subtrair){

 

$total = ($valor1 - $valor2);

echo "$total";

}

elseif ($opcao == multiplicar){

 

$total = ($valor1 * $valor2);

echo "$total";

}

elseif ($opcao == dividir){

 

$total = ($valor1 / $valor2);

echo "$total";

}

else {

 

echo "Opção invalida";

}

 

echo "<img src='calculadora 1.jpg'>";

?>

<body>

<form action="calculadora_teste.php" method="get">

<table>

<tr>

<td><h4>Calculadora</h4></td>

</tr>

<tr>

<td colspan="2"><hr /></td>

</tr>

<tr>

<td>Valor1

<input type="text" name="valor1" id="valor1" size="5" maxlength="5" />

<td><select name="opcao" id="opcao">

<option>Selecione</option>

<option value="somar">+ somar</option>

<option value="subtrair">- subtrair</option>

<option value="multiplicar">* multiplicar</option>

<option value="dividir">/ dividir</option>

</select>

Valor2

<input type="text" name="valor2" id="valor2" size="5" maxlength="5" />

=

<input type="text" name="total" id="total" value="<?= $total ?>" size="5" maxlength="10"/></td>

</tr>

<tr>

<td><input type="submit" name="igual" id="igual" value="calcular" /> </td>

</tr>

</table>

</form>

 

 

</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera a minha calculadora basica funciona de boa no Linux mais na hora que executo ela no windows não!

Estou utilizando o metodo GET e o erro da na linha 63 onde não consigo emprimir o resultado!

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Calculadora</title>

</head>

<?php

 

$valor1 = $_GET['valor1'];

$valor2 = $_GET['valor2'];

$opcao = $_GET['opcao'];

$total = $_GET['total'];

 

if ($opcao == somar){

 

$total = ($valor1 + $valor2);

echo "$total";

}

elseif ($opcao == subtrair){

 

$total = ($valor1 - $valor2);

echo "$total";

}

elseif ($opcao == multiplicar){

 

$total = ($valor1 * $valor2);

echo "$total";

}

elseif ($opcao == dividir){

 

$total = ($valor1 / $valor2);

echo "$total";

}

else {

 

echo "Opção invalida";

}

 

echo "<img src='calculadora 1.jpg'>";

?>

<body>

<form action="calculadora_teste.php" method="get">

<table>

<tr>

<td><h4>Calculadora</h4></td>

</tr>

<tr>

<td colspan="2"><hr /></td>

</tr>

<tr>

<td>Valor1

<input type="text" name="valor1" id="valor1" size="5" maxlength="5" />

<td><select name="opcao" id="opcao">

<option>Selecione</option>

<option value="somar">+ somar</option>

<option value="subtrair">- subtrair</option>

<option value="multiplicar">* multiplicar</option>

<option value="dividir">/ dividir</option>

</select>

Valor2

<input type="text" name="valor2" id="valor2" size="5" maxlength="5" />

=

<input type="text" name="total" id="total" value="<?= $total ?>" size="5" maxlength="10"/></td>

</tr>

<tr>

<td><input type="submit" name="igual" id="igual" value="calcular" /> </td>

</tr>

</table>

</form>

 

 

</body>

</html>

 

O erro que ocorreu aqui foram os seguintes:

Notice: Use of undefined constant somar - assumed 'somar' in ... on line 14

Notice: Use of undefined constant subtrair - assumed 'subtrair' in ... on line 19

Notice: Use of undefined constant multiplicar - assumed 'multiplicar' in ... on line 24

Notice: Use of undefined constant dividir - assumed 'dividir' in ... on line 29

 

Estavam ocorrendo pela falta das aspas nos IFs, porém trabalhava perfeitamente. Ficou assim:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calculadora</title>
</head>
<?php

$valor1 = $_GET['valor1'];
$valor2 = $_GET['valor2'];
$opcao = $_GET['opcao'];
$total = $_GET['total'];

if ($opcao == "somar"){

$total = ($valor1 + $valor2);
echo "$total";
}
elseif ($opcao == "subtrair"){

$total = ($valor1 - $valor2);
echo "$total";
}
elseif ($opcao == "multiplicar"){

$total = ($valor1 * $valor2);
echo "$total";
}
elseif ($opcao == "dividir"){

$total = ($valor1 / $valor2);
echo "$total";
}
else {

echo "Opção invalida";
}

echo "<img src='calculadora 1.jpg'>";
?>
<body>
<form method="get">
<table>
<tr>
<td><h4>Calculadora</h4></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td>Valor1
<input type="text" name="valor1" id="valor1" size="5" maxlength="5" />
<td><select name="opcao" id="opcao">
<option>Selecione</option>
<option value="somar">+ somar</option>
<option value="subtrair">- subtrair</option>
<option value="multiplicar">* multiplicar</option>
<option value="dividir">/ dividir</option>
</select>
Valor2
<input type="text" name="valor2" id="valor2" size="5" maxlength="5" /> 
=
<input type="text" name="total" id="total" value="<?= $total ?>" size="5" maxlength="10"/></td>
</tr>
<tr>
<td><input type="submit" name="igual" id="igual" value="calcular" /> </td>
</tr>
</table>
</form>


</body>
</html>

 

Teste e me diga no que deu. Espero ter ajudado.

 

Abraços,

bigCheat.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Erro que me percegue kkk

 

<input type="text" name="total" id="total" value="<?= $total ?>" size="5" maxlength="10"/></td>

 

Ainda continua na linha 62 e no caso no campo onde deveria mostrar o resultado do calculo ele mostra isso .<?= $total ?>

 

Abraco! Mais tem mais alguma dica?

Compartilhar este post


Link para o post
Compartilhar em outros sites

o erro é porque você esta usando shorttags (tags abreviadas), evite-as...

 

em vez de:

 

<?= $total ?>

 

faça:

 

<?php echo $total; ?>

 

e também vai dar erro lá em cima, pois quando você chama o script as variáveis:

$valor1 = $_GET['valor1'];

$valor2 = $_GET['valor2'];

$opcao = $_GET['opcao'];

$total = $_GET['total'];

 

ainda não existem, por isso eu coloquei um isset, que verifica se o formulário foi postado... veja o código:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Calculadora</title>
</head>
<?php

if(isset($_GET['igual'])) {
$valor1 = $_GET['valor1'];
$valor2 = $_GET['valor2'];
$opcao = $_GET['opcao'];
$total = $_GET['total'];

if ($opcao == "somar"){

$total = ($valor1 + $valor2);
echo "$total";
}
elseif ($opcao == "subtrair"){

$total = ($valor1 - $valor2);
echo "$total";
}
elseif ($opcao == "multiplicar"){

$total = ($valor1 * $valor2);
echo "$total";
}
elseif ($opcao == "dividir"){

$total = ($valor1 / $valor2);
echo "$total";
}
else {

echo "Opção invalida";
}

echo "<img src='calculadora 1.jpg'>";
}
?>
<body>
<form method="get">
<table>
<tr>
<td><h4>Calculadora</h4></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td>Valor1
<input type="text" name="valor1" id="valor1" size="5" maxlength="5" />
<td><select name="opcao" id="opcao">
<option>Selecione</option>
<option value="somar">+ somar</option>
<option value="subtrair">- subtrair</option>
<option value="multiplicar">* multiplicar</option>
<option value="dividir">/ dividir</option>
</select>
Valor2
<input type="text" name="valor2" id="valor2" size="5" maxlength="5" />
=
<input type="text" name="total" id="total" value="<?php if(isset($total)){ echo $total; } ?>" size="5" maxlength="10"/></td>
</tr>
<tr>
<td><input type="submit" name="igual" id="igual" value="calcular" /> </td>
</tr>
</table>
</form>


</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera a minha calculadora basica funciona de boa no Linux mais na hora que executo ela no windows não!

Estou utilizando o metodo GET e o erro da na linha 63 onde não consigo emprimir o resultado!

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Calculadora</title>

</head>

<?php

 

$valor1 = $_GET['valor1'];

$valor2 = $_GET['valor2'];

$opcao = $_GET['opcao'];

$total = $_GET['total'];

 

if ($opcao == somar){

 

$total = ($valor1 + $valor2);

echo "$total";

}

elseif ($opcao == subtrair){

 

$total = ($valor1 - $valor2);

echo "$total";

}

elseif ($opcao == multiplicar){

 

$total = ($valor1 * $valor2);

echo "$total";

}

elseif ($opcao == dividir){

 

$total = ($valor1 / $valor2);

echo "$total";

}

else {

 

echo "Opção invalida";

}

 

echo "<img src='calculadora 1.jpg'>";

?>

<body>

<form action="calculadora_teste.php" method="get">

<table>

<tr>

<td><h4>Calculadora</h4></td>

</tr>

<tr>

<td colspan="2"><hr /></td>

</tr>

<tr>

<td>Valor1

<input type="text" name="valor1" id="valor1" size="5" maxlength="5" />

<td><select name="opcao" id="opcao">

<option>Selecione</option>

<option value="somar">+ somar</option>

<option value="subtrair">- subtrair</option>

<option value="multiplicar">* multiplicar</option>

<option value="dividir">/ dividir</option>

</select>

Valor2

<input type="text" name="valor2" id="valor2" size="5" maxlength="5" />

=

<input type="text" name="total" id="total" value="<?= $total ?>" size="5" maxlength="10"/></td>

</tr>

<tr>

<td><input type="submit" name="igual" id="igual" value="calcular" /> </td>

</tr>

</table>

</form>

 

 

</body>

</html>

 

 

Sugiro usar o código php da seguinte forma:

 

<?php

 

isset($_GET['valor1]) ? $valor1 = $_GET['valor1'] : $valor1 = "";

isset($_GET['valor2]) ? $valor2 = $_GET['valor1'] : $valor2 = "";

isset($_GET['opcao]) ? $opcao = $_GET['valor1'] : $opcao = "";

isset($_GET['total]) ? $total = $_GET['total'] : $total = "";

 

if ($opcao == "somar"){

 

$total = ($valor1 + $valor2);

echo "$total";

}

elseif ($opcao == "subtrair"){

 

$total = ($valor1 - $valor2);

echo "$total";

}

elseif ($opcao == "multiplicar"){

 

$total = ($valor1 * $valor2);

echo "$total";

}

elseif ($opcao == "dividir"){

 

$total = ($valor1 / $valor2);

echo "$total";

}

else {

 

echo "Opção invalida";

}

 

echo "<img src='calculadora 1.jpg'>";

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.